You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every *LiteralExpr AST node has an Initializer member variable or equivalent, and a large subset of them have a second BuiltinInitializer member variable. However, each subclass declares its own copies of these. This leads to a lot of unnecessary duplication; for instance, SILGenFunction::emitLiteral() has about a dozen lines that merely call getInitializer() or getBuiltinInitializer() on various subclasses.
You could improve this situation by refactoring the LiteralExpr subclasses:
Rename InterpolatedStringLiteralExpr::get/setResultInit() to get/setInitializer() and update use sites so that it matches the convention of the other literal expressions
Hoist the Initializer member variable and its accessor methods into LiteralExpr
Introduce a new subclass with the BuiltinInitializer member variable and its accessor methods
Make all the literals with {{BuiltinInitializer}}s subclasses of that new class
Audit the call sites of getInitializer(), setInitializer(), getBuiltinInitializer(), and setBuiltinInitializer() to see how much code you can now consolidate
Since you're changing the hierarchy of Expr subclasses, you'll need to update include/swift/AST/ExprNodes.def. The comments at the top of the file should help you do that.
This task should not cause any changes in functionality—it's just a straight-up refactoring and simplification—so if you've done this correctly, all existing tests should pass and you won't need to write any new ones.
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: ead22ff9893454d26c131a8334ef82dd
Issue Description:
Every
*LiteralExpr
AST node has anInitializer
member variable or equivalent, and a large subset of them have a secondBuiltinInitializer
member variable. However, each subclass declares its own copies of these. This leads to a lot of unnecessary duplication; for instance,SILGenFunction::emitLiteral()
has about a dozen lines that merely callgetInitializer()
orgetBuiltinInitializer()
on various subclasses.You could improve this situation by refactoring the
LiteralExpr
subclasses:Rename
InterpolatedStringLiteralExpr::get/setResultInit()
toget/setInitializer()
and update use sites so that it matches the convention of the other literal expressionsHoist the
Initializer
member variable and its accessor methods intoLiteralExpr
Introduce a new subclass with the
BuiltinInitializer
member variable and its accessor methodsMake all the literals with {{BuiltinInitializer}}s subclasses of that new class
Audit the call sites of
getInitializer()
,setInitializer()
,getBuiltinInitializer()
, andsetBuiltinInitializer()
to see how much code you can now consolidateSince you're changing the hierarchy of
Expr
subclasses, you'll need to updateinclude/swift/AST/ExprNodes.def
. The comments at the top of the file should help you do that.This task should not cause any changes in functionality—it's just a straight-up refactoring and simplification—so if you've done this correctly, all existing tests should pass and you won't need to write any new ones.
The text was updated successfully, but these errors were encountered: