mirror of
https://github.com/Noratrieb/riverdelta.git
synced 2026-01-14 08:25:02 +01:00
fix cycles in extern modules
This commit is contained in:
parent
3af8f4fc40
commit
a699262671
2 changed files with 23 additions and 3 deletions
|
|
@ -22,6 +22,8 @@ export type CrateLoader = (
|
|||
export class GlobalContext {
|
||||
public error: ErrorHandler = new ErrorHandler();
|
||||
public finalizedCrates: Crate<Final>[] = [];
|
||||
// For cycle detection.
|
||||
public cratesBeingLoaded: Set<string> = new Set<string>();
|
||||
public crateId: Ids = new Ids();
|
||||
|
||||
constructor(public opts: Options, public crateLoader: CrateLoader) {}
|
||||
|
|
|
|||
|
|
@ -90,9 +90,7 @@ export const loadCrate: CrateLoader = (
|
|||
name: string,
|
||||
span: Span,
|
||||
): DepCrate => {
|
||||
// We really, really want a good algorithm for finding crates.
|
||||
// But right now we just look for files in the CWD.
|
||||
|
||||
// If we've loaded the crate already, great.
|
||||
const existing = gcx.finalizedCrates.find(
|
||||
(crate) => crate.packageName === name,
|
||||
);
|
||||
|
|
@ -102,6 +100,24 @@ export const loadCrate: CrateLoader = (
|
|||
|
||||
const crateId = gcx.crateId.next();
|
||||
|
||||
// If we have not loaded the crate yet, we may actually already be loading it.
|
||||
// A cycle!!
|
||||
if (gcx.cratesBeingLoaded.has(name)) {
|
||||
return dummyErrorCrate(
|
||||
crateId,
|
||||
name,
|
||||
gcx.error.emit(
|
||||
new CompilerError(`cycle detected loading extern module ${name}`, span),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Let's start loading the crate!
|
||||
gcx.cratesBeingLoaded.add(name);
|
||||
|
||||
// We really, really want a good algorithm for finding crates.
|
||||
// But right now we just look for files in the CWD.
|
||||
|
||||
const file = loadModuleFile(".", name, span);
|
||||
if (!file.ok) {
|
||||
return dummyErrorCrate(crateId, name, gcx.error.emit(file.err));
|
||||
|
|
@ -122,5 +138,7 @@ export const loadCrate: CrateLoader = (
|
|||
const typecked = typeck(gcx, resolved);
|
||||
|
||||
gcx.finalizedCrates.push(typecked);
|
||||
// Crate is loaded, no cycles.
|
||||
gcx.cratesBeingLoaded.delete(name);
|
||||
return typecked;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue