Skip to content

Commit

Permalink
[GR-18987] Deferring contextExtensions creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzezula committed Oct 25, 2019
1 parent a872975 commit 04799d1
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public abstract static class Loader implements LLVMCapability {
}

public List<ContextExtension> getLanguageContextExtension() {
verifyContextExtensionsInitialized();
return contextExtensions;
}

Expand All @@ -109,6 +110,7 @@ public <T extends ContextExtension> T getContextExtension(Class<T> type) {

public <T extends ContextExtension> T getContextExtensionOrNull(Class<T> type) {
CompilerAsserts.neverPartOfCompilation();
verifyContextExtensionsInitialized();
for (ContextExtension ce : contextExtensions) {
if (ce.extensionClass() == type) {
return type.cast(ce);
Expand All @@ -117,6 +119,13 @@ public <T extends ContextExtension> T getContextExtensionOrNull(Class<T> type) {
return null;
}

private void verifyContextExtensionsInitialized() {
CompilerAsserts.neverPartOfCompilation();
if (contextExtensions == null) {
throw new IllegalStateException("LLVMContext is not yet initialized");
}
}

/**
* Do not use this on fast-path.
*/
Expand Down Expand Up @@ -167,14 +176,14 @@ protected LLVMContext createContext(Env env) {

Toolchain toolchain = new ToolchainImpl(activeConfiguration.getCapability(ToolchainConfig.class), this);
env.registerService(toolchain);
this.contextExtensions = activeConfiguration.createContextExtensions(env);

LLVMContext context = new LLVMContext(this, env, getLanguageHome(), toolchain);
return context;
}

@Override
protected void initializeContext(LLVMContext context) {
this.contextExtensions = activeConfiguration.createContextExtensions(context.getEnv());
context.initialize();
}

Expand Down

0 comments on commit 04799d1

Please sign in to comment.