Beef icon indicating copy to clipboard operation
Beef copied to clipboard

Builtin CustomAttributes not always working when typealiased

Open EinScott opened this issue 4 years ago • 0 comments

context: https://github.com/beefytech/Beef/pull/1019

I would want to use a typealias for at least SkipCall (what i have been doing for some time, but now realize never worked). I've done some testing on at least the common attributes (even though most of them probably have no apparent reason to be aliased) and collected how they are handled where i could find it (which is hope is accurate):

// Expectation: everything that is only name match doesnt work, with BfCustomAttributes it should work
// No idea on the ones with no comments
// Expected to not work (from code mentions): MangleConst, NoReturn, NoSplat, SkipCall, ApllowAppend, NoShow, Commutable
// Out-liars (possibly incomplete): AlwaysInclude, Inline, CLink, NoDiscard, Comptime, Unchecked (and maybe related ones)

typealias InlAttribute = InlineAttribute; // DOESNT WORK (handled via BfCustomAttributes & defBuilder name match)
typealias AwiAttribute = AlwaysIncludeAttribute; // DOESNT WORK (but works if it was proper AlwaysInclude before)
// -> (handled in ProcesssTypeInstCustomAttributes & defBuilder name match)
typealias RflAttribute = ReflectAttribute; // ? (handled via BfCustomAttributes)
typealias UnbAttribute = UnboundAttribute; // ? (handled via BfCustomAttributes)
typealias FndAttribute = FriendAttribute; // Works (handled via BfCustomAttributes)
typealias NexAttribute = NoExtensionAttribute; // ? (handled via BfCustomAttributes)
typealias IerAttribute = IgnoreErrorsAttribute; // Works (handled via BfCustomAttributes)
typealias OptAttribute = OptimizeAttribute; // Works
typealias NodAttribute = NoDebugAttribute;
typealias UlmAttribute = UseLLVMAttribute;
typealias ClkAttribute = CLinkAttribute; // DOESNT WORK (handled via BfCustomAttributes & defBuilder name match)
typealias LinAttribute = LinkNameAttribute; // Works (handled via BfCustomAttributes)
typealias MncAttribute = MangleConstAttribute; // ? (bfMangler name match)
typealias ClcAttribute = CallingConventionAttribute; // ? (handled via BfCustomAttributes)
// typealias StcAttribute = StdCallAttribute; // (defBuilder name match)
// -> on delegates and functions it only searches for StdCall?
typealias NrtAttribute = NoReturnAttribute; // DOESNT WORK (defBuilder name match)
typealias NspAttribute = NoSplatAttribute; // ? (defBuilder name match)
typealias SclAttribute = SkipCallAttribute; // DOESNT WORK (defBuilder name match)
typealias OncAttribute = OnCompileAttribute; // Works (defBuilder name match & handled via BfCustomAttributes)
typealias CptAttribute = ComptimeAttribute; // DOESNT WORK (defBuilder name match & handled via BfCustomAttributes)
typealias CteAttribute = ConstEvalAttribute; // ? (handled via BfCustomAttributes)
typealias ItrAttribute = IntrinsicAttribute;
typealias SipAttribute = StaticInitPriorityAttribute;
typealias SiaAttribute = StaticInitAfterAttribute;
typealias FadAttribute = ForceAddrAttribute;
typealias AlpAttribute = AllowAppendAttribute; // DOESNT WORK (defBuilder name match)
typealias PckAttribute = PackedAttribute; // Works (handled in ProcesssTypeInstCustomAttributes)
typealias AlgAttribute = AlignAttribute; // ? (handled in ProcesssTypeInstCustomAttributes)
typealias AldAttribute = AllowDuplicatesAttribute; // Works (handled via BfCustomAttributes)
typealias UniAttribute = UnionAttribute; // ? (handled in ProcesssTypeInstCustomAttributes)
typealias CrpAttribute = CReprAttribute; // Works (handled in ProcesssTypeInstCustomAttributes)
typealias OrdAttribute = OrderedAttribute; // ? (handled in ProcesssTypeInstCustomAttributes)
typealias UlaAttribute = UnderlyingArrayAttribute; // ?
// -> (handled in ProcesssTypeInstCustomAttributes & handled via BfCustomAttributes)
typealias NswAttribute = NoShowAttribute; // DOESNT WORK (defBuilder name match)
typealias HnaAttribute = HideNameAttribute;
typealias TstAttribute = TestAttribute; // Works (handled via BfCustomAttributes)
typealias ImpAttribute = ImportAttribute; // ? (defBuilder name match & handled via BfCustomAttributes)
typealias ExpAttribute = ExportAttribute; // ? (defBuilder name match & handled via BfCustomAttributes)
typealias ThsAttribute = ThreadStaticAttribute; // ? (defBuilder name match & handled via BfCustomAttributes)
typealias ChkAttribute = CheckedAttribute; // ? (handled via BfCustomAttributes & defBuilder name match)
typealias UckAttribute = UncheckedAttribute; // DOESNT WORK (handled via BfCustomAttributes & defBuilder name match)
typealias DckAttribute = DisableChecksAttribute; // ? (handled via BfCustomAttributes)
typealias DoaAttribute = DisableObjectAccessChecksAttribute; // ? (handled via BfCustomAttributes)
typealias ObsAttribute = ObsoleteAttribute; // Works (handled via BfCustomAttributes)
typealias CmuAttribute = CommutableAttribute; // DOESNT WORK (defBuilder name match)
typealias ErrAttribute = ErrorAttribute; // Works (handled via BfCustomAttributes)
typealias WrnAttribute = WarnAttribute; // Works (handled via BfCustomAttributes)
typealias NdcAttribute = NoDiscardAttribute; // DOESNT WORK (defBuilder name match & handled via BfCustomAttributes)
// -> because defBuilder var is required to be set, BfCustomAttributes just gets for args!
typealias AtuAttribute = AttributeUsageAttribute; // Works (handled via BfCustomAttributes)

I randomly came across what i think is the cause for NoDiscord not working, but i either have no idea why or havent looked into the other ones.

Lastly, some code for testing:

[Atu(.Class)]
struct BAttribute : Attribute
{

}

[Crp/*,Pck*/]
struct A
{
	uint8 a, b, c;
	float t;

	// Size [CRepr]: 8, [Packed,CRepr]: 7, Beef:7
}

//[Awi]
class Other
{
	static this()
	{
		Debug.WriteLine("Hello");
	}

	static void P() {}
}

/*[Ald]
enum Eeee
{
	Zero = 0,
	Null = 0
}*/

// Shows up as (Optimized) in callstack
//[Opt]
class Program
{
	//[Comptime]
	[Cpt]
	static void CT()
	{
		Runtime.FatalError();
	}

	//[OnCompile(.TypeD)] // .TypeDone... just crashes on AssertErrorState (debugIDE) huh
	//[Onc(.Typ)] // Because this also crashes... that means it works?
	static void Compile()
	{
		// trying to make this an empty multilinestring by typing " also likely crashes
		//Compiler.EmitTypeBody(typeof(Self), "");
	}

	[Tst]
	public static void T()
	{
		Test.FatalError("Oh no");
	}

	[Ths] // ???
	public static Self aaaa;

	/*[Alp]
	public this()
	{
		let ptr = append uint8[4];
	}*/

	public static void Main()
	{
		
		//W();
		//E();
		//O();

		/*let s = scope Program();
		let d = 1 + s;*/ // Doesnt work

		//GetMeAThing(); // doesnt work
		//LinkMe(); // doesnt work

		/*[Ier]
		{
			String s = 1 + 2;
		}*/

		//Other.[Fnd]P();

		//I(); // (not inlined)

		/*{
			N(); // Doesnt work
			int i = 1 + 2;
		}*/

		//Debug.WriteLine(scope $"{sizeof(A)}");

		//S();

		//SEE

		/*[B]
		{

		}*/

		//CT(); // Doesnt work

		//C(); // Doesnt work
	}

	//[Unchecked]
	[Uck]
	public static void C()
	{

	}

	[Nsw]
	public static void SEEEECRET()
	{

	}

	[Scl]
	public static void S()
	{
		Debug.WriteLine("AHHHHHHHHHH");
	}	

	[Nrt]
	public static void N()
	{

	}

	[Inl]
	public static void I()
	{
		int i = 1 + 4;
		Console.Write(i);
	}

	[Wrn("WARN")]
	public static void W()
	{

	}

	[Err("ERR")]
	public static void E()
	{

	}

	[Obs("OBS", false)]
	public static void O()
	{

	}

	[Cmu]
	public static Self operator+(Self a, int i)
	{
		return a;
	}

	[Ndc]
	static Self GetMeAThing()
	{
		return null;
	}

	// Look at unresolved Symbol name, should be just "LinkeMe" if its working
	[Clk]
	public static extern void LinkMe();
}

EinScott avatar May 30 '21 09:05 EinScott