Skip to content
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

compiler: getGlobalDeclaration() takes a NonLocalBinding #29189

Merged
merged 3 commits into from
May 24, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Effect,
FunctionType,
IdentifierId,
NonLocalBinding,
PolyType,
ScopeId,
Type,
Expand Down Expand Up @@ -511,7 +512,8 @@ export class Environment {
return this.#hoistedIdentifiers.has(node);
}

getGlobalDeclaration(name: string): Global | null {
getGlobalDeclaration(binding: NonLocalBinding): Global | null {
const name = binding.name;
let resolvedName = name;

if (this.config.hookPattern != null) {
Expand All @@ -534,6 +536,7 @@ export class Environment {
log(() => `Undefined global \`${name}\``);
}
}

return resolvedGlobal;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Binding, NodePath } from "@babel/traverse";
import * as t from "@babel/types";
import { CompilerError } from "../CompilerError";
import { Environment } from "./Environment";
import { Global } from "./Globals";
import {
BasicBlock,
BlockId,
Expand Down Expand Up @@ -186,25 +185,6 @@ export default class HIRBuilder {
};
}

resolveGlobal(
path: NodePath<t.Identifier | t.JSXIdentifier>
): (Global & { name: string }) | null {
const name = path.node.name;
const resolvedGlobal = this.#env.getGlobalDeclaration(name);
if (resolvedGlobal) {
return {
...resolvedGlobal,
name,
};
} else {
// if env records no global with the given name, load it as an unknown type
return {
kind: "Poly",
name,
};
}
}

#resolveBabelBinding(
path: NodePath<t.Identifier | t.JSXIdentifier>
): Binding | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function collectTemporaries(
break;
}
case "LoadGlobal": {
const global = env.getGlobalDeclaration(value.binding.name);
const global = env.getGlobalDeclaration(value.binding);
const hookKind = global !== null ? getHookKindForType(env, global) : null;
const lvalId = instr.lvalue.identifier.id;
if (hookKind === "useMemo" || hookKind === "useCallback") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function* generateInstructionTypes(
}

case "LoadGlobal": {
const globalType = env.getGlobalDeclaration(value.binding.name);
const globalType = env.getGlobalDeclaration(value.binding);
if (globalType) {
yield equation(left, globalType);
}
Expand Down