Skip to content

[ArchetypeBuilder] Eliminate expandGenericEnvironment(). #7383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions include/swift/AST/ArchetypeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ class ArchetypeBuilder {
RequirementSource Source,
llvm::SmallPtrSetImpl<ProtocolDecl *> &Visited);

/// "Expand" all of the archetypes in the generic environment.
/// FIXME: This is a hack we need until we're able to lazily create
/// archetypes.
void expandGenericEnvironment(GenericEnvironment *genericEnv);

public:
/// \brief Add a new conformance requirement specifying that the given
/// potential archetypes are equivalent.
Expand Down
58 changes: 0 additions & 58 deletions lib/AST/ArchetypeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2601,61 +2601,3 @@ GenericSignature *ArchetypeBuilder::getGenericSignature() {
auto sig = GenericSignature::get(Impl->GenericParams, requirements);
return sig;
}

void ArchetypeBuilder::expandGenericEnvironment(GenericEnvironment *env) {

assert(Impl->finalized && "Must finalize builder first");

// Force the creation of all of the archetypes.
// FIXME: This isn't a well-formed notion with recursive protocol constraints.
auto signature = env->getGenericSignature();
visitPotentialArchetypes([&](PotentialArchetype *pa) {
if (auto archetype =
env->mapTypeIntoContext(
pa->getDependentType(signature->getGenericParams(),
/*allowUnresolved=*/false),
getLookupConformanceFn())
->getAs<ArchetypeType>())
(void)archetype->getAllNestedTypes();
});

#ifndef NDEBUG
// FIXME: This property should be maintained when there are errors, too.
if (!Diags.hadAnyError()) {
auto genericParams = signature->getGenericParams();
visitPotentialArchetypes([&](PotentialArchetype *pa) {
if (pa->isConcreteType()) return;

auto depTy = pa->getDependentType(genericParams,
/*allowUnresolved=*/false);
auto inContext = env->mapTypeIntoContext(depTy, getLookupConformanceFn());

auto repDepTy = pa->getRepresentative()->getDependentType(
genericParams,
/*allowUnresolved=*/false);
auto repInContext =
env->mapTypeIntoContext(repDepTy, getLookupConformanceFn());
if (!(inContext->isEqual(repInContext) ||
inContext->hasError() ||
repInContext->hasError())) {
dump(llvm::errs());

llvm::errs() << "Dependent type:\n";
depTy->dump();

llvm::errs() << "Dependent type in context:\n";
inContext->dump();

llvm::errs() << "Representative dependent type:\n";
repDepTy->dump();

llvm::errs() << "Representative in context:\n";
repInContext->dump();

llvm_unreachable(
"Potential archetype mapping differs from representative!");
}
});
}
#endif
}
4 changes: 1 addition & 3 deletions lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ GenericSignature::getCanonicalSignature() const {
GenericEnvironment *GenericSignature::createGenericEnvironment(
ModuleDecl &mod) {
auto *builder = getArchetypeBuilder(mod);
auto env = GenericEnvironment::getIncomplete(this, builder);
builder->expandGenericEnvironment(env);
return env;
return GenericEnvironment::getIncomplete(this, builder);
}


Expand Down