It's a while since I looked at this but I'm fairly sure that if you provide a signature that Poly/ML will recheck the structure against the signature. It may be possible to avoid this in specific situations but there are a lot of cases where things get complicated. For example, the signature name FOO may be rebound or there may be sharing constraints if FOO is actually used within another signature. Opaque signatures are more complicated since structure X :> FOO = Foo; results in new type names being created for all the bound type names in FOO. Similarly, when matching an actual functor argument against a formal argument the compiler needs to create a map for the type names so that the correct types are generated for the result structure.
I guess it may be possible to avoid looking at the value environment in these cases and since that's usually much bigger than the type environment there would be some saving. There would need to be a unique ID for a signature to pick up the case of the signature name being rebound.
David
On 27/06/2011 17:26, Aleks Kissinger wrote:
Why are repeated signature ascriptions slow? Suppose Foo is a pretty big structure, which has already been ascribed the signature FOO:
structure X = Foo; (* fast, note that poly already knows Foo, and thus X, is a FOO *)
structure X : FOO
structure X = Foo : FOO (* slow *)
structure X : FOO
structure X : FOO = Foo (* slow *)
structure X : FOO
Poly already knows that Foo is a FOO, so surely this should return instantly, but it acts like its typechecking the whole struct again. While it's not necessary to do the ascriptions above (poly is smart enough to figure out X is a FOO, even in the first case), this same issue seems to be seriously slowing down functor evaluation, where you can't avoid ascription.
I thought using opaque ascription might skirt the issue, but the same thing happens. Is poly just being silly, or this this a consequence of how the type system works?
a _______________________________________________ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml