Skip to content

Freezes parsed AST nodes to be immutable#839

Open
skberkeley wants to merge 1 commit intoprimaryfrom
skberkeley/freeze-astnodes
Open

Freezes parsed AST nodes to be immutable#839
skberkeley wants to merge 1 commit intoprimaryfrom
skberkeley/freeze-astnodes

Conversation

@skberkeley
Copy link
Contributor

This is a prerequisite for making AST APIs available in Engine

@skberkeley skberkeley self-assigned this Feb 21, 2026
@skberkeley skberkeley added runtime Work in the C++ runtime portion of the code std Work in the Luau standard library portion of the code labels Feb 21, 2026
Copy link
Contributor

@hgoldstein hgoldstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to freeze the table made in the constructor for AstSerialize? What about the location structs? Mainly I think you need to handle incomplete ASTs.

One question I have is: how bad would it be if we "deep froze" the table at the very end? Just recurse through the table itself rather than freeze at every junction when serializing.

luaL_error(L, "parsing failed:\n%s", fullError.c_str());
}

lua_rawcheckstack(L, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?


// For correct trivia computation, everything must end up going through serializeToken
void serializeToken(Luau::Position position, const char* text, int nrec = 0)
void serializeToken(Luau::Position position, const char* text, int nrec = 0, bool freezeToken = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have an extra argument here?

Comment on lines +1289 to +1290
// Lute isn't in the business of serializing incomplete ASTs
LUAU_ASSERT(node->hasThen);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that true? I feel like if you were implementing, say, an LSP on top of Lute, you might expect that the AST you're given is incomplete (because the user is writing it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

runtime Work in the C++ runtime portion of the code std Work in the Luau standard library portion of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants