@@ -6328,10 +6328,9 @@ class LibraryElementImpl extends ElementImpl
63286328 /// an entry point.
63296329 FunctionElement ? _entryPoint;
63306330
6331- /// The element representing the synthetic function `loadLibrary` that is
6332- /// defined for this library, or `null` if the element has not yet been
6333- /// created.
6334- late FunctionElement _loadLibraryFunction;
6331+ /// The provider for the synthetic function `loadLibrary` that is defined
6332+ /// for this library.
6333+ late final LoadLibraryFunctionProvider loadLibraryProvider;
63356334
63366335 @override
63376336 int nameLength;
@@ -6605,13 +6604,14 @@ class LibraryElementImpl extends ElementImpl
66056604 }
66066605
66076606 @override
6608- FunctionElement get loadLibraryFunction {
6609- return _loadLibraryFunction ;
6607+ FunctionElementImpl get loadLibraryFunction {
6608+ return loadLibraryFunction2.firstFragment ;
66106609 }
66116610
66126611 @override
6613- TopLevelFunctionElement get loadLibraryFunction2 =>
6614- loadLibraryFunction as TopLevelFunctionElement ;
6612+ TopLevelFunctionElementImpl get loadLibraryFunction2 {
6613+ return loadLibraryProvider.getElement (this );
6614+ }
66156615
66166616 @override
66176617 List <ElementAnnotationImpl > get metadata {
@@ -6732,18 +6732,6 @@ class LibraryElementImpl extends ElementImpl
67326732 builder.writeLibraryElement (this );
67336733 }
67346734
6735- /// Create the [FunctionElement] to be returned by [loadLibraryFunction] .
6736- /// The [typeProvider] must be already set.
6737- void createLoadLibraryFunction () {
6738- var fragment = FunctionElementImpl (FunctionElement .LOAD_LIBRARY_NAME , - 1 )
6739- ..enclosingElement3 = library
6740- ..isSynthetic = true
6741- ..returnType = typeProvider.futureDynamicType;
6742- _loadLibraryFunction = fragment;
6743- // TODO(scheglov): create it sooner, with actual reference.
6744- TopLevelFunctionElementImpl (Reference .root (), fragment);
6745- }
6746-
67476735 @override
67486736 ClassElement ? getClass (String name) {
67496737 for (var unitElement in units) {
@@ -6959,6 +6947,38 @@ class LibraryImportElementImpl extends _ExistingElementImpl
69596947 }
69606948}
69616949
6950+ /// The provider for the lazily created `loadLibrary` function.
6951+ final class LoadLibraryFunctionProvider {
6952+ final Reference fragmentReference;
6953+ final Reference elementReference;
6954+ TopLevelFunctionElementImpl ? _element;
6955+
6956+ LoadLibraryFunctionProvider ({
6957+ required this .fragmentReference,
6958+ required this .elementReference,
6959+ });
6960+
6961+ TopLevelFunctionElementImpl getElement (LibraryElementImpl library) {
6962+ return _element ?? = _create (library);
6963+ }
6964+
6965+ TopLevelFunctionElementImpl _create (LibraryElementImpl library) {
6966+ var name = FunctionElement .LOAD_LIBRARY_NAME ;
6967+
6968+ var fragment = FunctionElementImpl (name, - 1 );
6969+ fragment.name2 = name;
6970+ fragment.isSynthetic = true ;
6971+ fragment.isStatic = true ;
6972+ fragment.returnType = library.typeProvider.futureDynamicType;
6973+ fragment.enclosingElement3 = library.definingCompilationUnit;
6974+
6975+ fragment.reference = fragmentReference;
6976+ fragmentReference.element = fragment;
6977+
6978+ return TopLevelFunctionElementImpl (elementReference, fragment);
6979+ }
6980+ }
6981+
69626982class LocalFunctionElementImpl extends ExecutableElementImpl2
69636983 with WrappedElementMixin
69646984 implements LocalFunctionElement {
0 commit comments