diff --git a/source/frontend/collector.cpp b/source/frontend/collector.cpp index be3a672c..1e0b06ea 100644 --- a/source/frontend/collector.cpp +++ b/source/frontend/collector.cpp @@ -93,13 +93,13 @@ namespace frontend // note that we're guaranteed (because that's the whole point) // that any module we encounter here will have had all of its dependencies checked already - std::vector> imports; + std::vector> imports; for(auto d : state->graph->getDependenciesOf(file)) { auto imported = d->to; - auto stree = state->dtrees[imported->name]->base; - iceAssert(stree); + auto dtree = state->dtrees[imported->name]; + iceAssert(dtree); ImportThing ithing { imported->name, d->ithing.importAs, d->ithing.pubImport, d->ithing.loc }; if(auto it = std::find_if(imports.begin(), imports.end(), [&ithing](const auto& x) -> bool { return x.first.name == ithing.name; }); @@ -110,7 +110,7 @@ namespace frontend ->postAndQuit(); } - imports.push_back({ ithing, stree }); + imports.push_back({ ithing, dtree }); } // i guess we always add prelude definitions? diff --git a/source/frontend/file.cpp b/source/frontend/file.cpp index 388ab41e..178a46e3 100644 --- a/source/frontend/file.cpp +++ b/source/frontend/file.cpp @@ -25,7 +25,6 @@ namespace frontend std::vector importIndices; bool didLex = false; - bool isLexing = false; }; static util::hash_map fileList; @@ -35,7 +34,7 @@ namespace frontend // break early if we can { auto it = fileList.find(fullPath); - if(it != fileList.end() && it->second.didLex) + if(it != fileList.end()) return it->second; } @@ -89,21 +88,13 @@ namespace frontend } } - Location pos; FileInnards& innards = fileList[fullPath]; - if(innards.isLexing) - { - warn("attempting to lex file while file is already being lexed, stop it"); - return innards; - } - { pos.fileID = getFileIDFromFilename(fullPath); innards.fileContents = std::move(fileContents); innards.lines = std::move(rawlines); - innards.isLexing = true; } lexer::TokenList& ts = innards.tokens; @@ -133,7 +124,6 @@ namespace frontend } innards.didLex = true; - innards.isLexing = false; return innards; } diff --git a/source/include/typecheck.h b/source/include/typecheck.h index c6c65c27..a8e4b0f1 100644 --- a/source/include/typecheck.h +++ b/source/include/typecheck.h @@ -110,14 +110,14 @@ namespace sst struct TypecheckState { - TypecheckState(StateTree* st) : dtree(new DefinitionTree(st)), stree(dtree->base) { } + TypecheckState(StateTree* st) : dtree(new DefinitionTree(st)), stree(dtree->base), typeDefnMap(dtree->typeDefnMap) { } std::string moduleName; DefinitionTree* dtree = 0; StateTree* stree = 0; - util::hash_map typeDefnMap; + util::hash_map& typeDefnMap; std::vector locationStack; @@ -207,7 +207,7 @@ namespace sst }; DefinitionTree* typecheck(frontend::CollectorState* cs, const parser::ParsedFile& file, - const std::vector>& imports, bool addPreludeDefinitions); + const std::vector>& imports, bool addPreludeDefinitions); StateTree* addTreeToExistingTree(StateTree* to, StateTree* from, StateTree* commonParent, bool pubImport, bool ignoreVis); diff --git a/source/typecheck/dotop.cpp b/source/typecheck/dotop.cpp index 4a0c7460..5352dfe2 100644 --- a/source/typecheck/dotop.cpp +++ b/source/typecheck/dotop.cpp @@ -462,6 +462,7 @@ static sst::Expr* doExpressionDotOp(sst::TypecheckState* fs, ast::DotOperator* d // ok. auto defn = fs->typeDefnMap[type]; + iceAssert(defn); if(auto str = dcast(sst::StructDefn, defn)) { diff --git a/source/typecheck/toplevel.cpp b/source/typecheck/toplevel.cpp index 705ccf51..77fa4271 100644 --- a/source/typecheck/toplevel.cpp +++ b/source/typecheck/toplevel.cpp @@ -296,8 +296,8 @@ namespace sst using frontend::CollectorState; - DefinitionTree* typecheck(CollectorState* cs, const parser::ParsedFile& file, const std::vector>& imports, - bool addPreludeDefinitions) + DefinitionTree* typecheck(CollectorState* cs, const parser::ParsedFile& file, + const std::vector>& imports, bool addPreludeDefinitions) { StateTree* tree = new StateTree(file.moduleName, file.name, 0); tree->treeDefn = util::pool(Location()); @@ -357,10 +357,11 @@ namespace sst iceAssert(insertPoint); - _addTreeToExistingTree(fs->dtree->thingsImported, insertPoint, import, /* commonParent: */ nullptr, ithing.pubImport, + _addTreeToExistingTree(fs->dtree->thingsImported, insertPoint, import->base, /* commonParent: */ nullptr, ithing.pubImport, /* ignoreVis: */ false, file.name); fs->dtree->thingsImported.insert(ithing.name); + fs->dtree->typeDefnMap.insert(import->typeDefnMap.begin(), import->typeDefnMap.end()); } if(addPreludeDefinitions) @@ -372,8 +373,6 @@ namespace sst tns->name = file.moduleName; fs->dtree->topLevel = tns; - - fs->dtree->typeDefnMap = fs->typeDefnMap; return fs->dtree; } }