Ambiguous mangling of symbols declared in nested scopes

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 17 17:20:26 PDT 2014


On Thu, Jul 17, 2014 at 10:15:56AM +0000, Dicebot via Digitalmars-d wrote:
> Slight correction : it is not a mangling of variable that is a problem
> (local variables don't have any mangling) but mangling of the function
> itself (it naively uses variable name for mangled name generation).
> Should use something like unique id instead.

Hmm. How to generate a unique id? It must be module-wide, but not
program-wide, because otherwise you get a different mangling depending
on the order of imports. It must not increment within the same scope:

	void myFunc(alias A)() { ... }
	void main() {
		{
			int i;

			// All 3 instances below should refer to the
			// same instantiation of myFunc.
			myFunc!i();
			myFunc!i();
			myFunc!i();
		}
		{
			int i, j;
			myFunc!i(); // but this one should be different
			{
				myFunc!i(); // this one should be same as previous line
				myFunc!j(); // this one should be different
			}
			myFunc!j(); // same as previous line
		}

Also, it should resolve ambiguities between identically-named inner
functions declared in nested scopes:

		void delegate() dg, dg2;
		{
			void inner() { ... }
			myFunc!inner();
			myFunc!inner(); // same as previous line
			dg = &inner;
		}
		{
			void inner() { ... }
			myFunc!inner(); // different from previous scope
			dg2 = &inner;
		}
		assert(dg !is dg2);
	}

So looks like we need to index scopes inside function bodies, perhaps by
number of scopes in preceding lexical position, and any inner function's
mangled name should somehow incorporate this index. Alias parameters
should also incorporate this index in the mangling of the resulting
template.


T

-- 
It only takes one twig to burn down a forest.


More information about the Digitalmars-d mailing list