-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Introduce GlobalVar
akin to LocalVar
and introduce get_global
instruction similar to get_local
.
#6928
base: master
Are you sure you want to change the base?
Conversation
…to vaivaswatha/ir_consts_1
CodSpeed Performance ReportMerging #6928 will not alter performanceComparing Summary
|
let reg = self.reg_seqr.next(); | ||
self.cur_bytecode.push(Op { | ||
opcode: either::Either::Left(VirtualOp::AddrDataId(reg.clone(), data_id.clone())), | ||
comment: "constant address in data section".into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Op::comment
s of other ops follow these guidelines. It would be good to be consistent here, it makes the reading of the printed ASM easier.
comment: "constant address in data section".into(), | |
comment: "get constant's address in data section".into(), |
if let Some(constant) = global_var.get_initializer(env.context) { | ||
return Ok(Some(Value::new_constant(env.context, *constant))); | ||
} | ||
Ok(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this actually happen? Shouldn't it actually be an ICE? GlobalVar
s are modeled as variables, means they do not necessarily need to have an initializer, that is fine. My question is the exact semantics of getting an uninitialized GlobalVar
in the context of const_eval
. We are compiling a const decl and we are getting a global_var
from the env.module
. It means it exists, but it doesn't have an initializer.
Doesn't this points to a bug somewhere before in the compilation chain and should be an ICE? Or am I missing some details?
sway-ir/src/parser.rs
Outdated
@@ -43,11 +43,12 @@ mod ir_builder { | |||
} | |||
|
|||
rule script_or_predicate() -> IrAstModule | |||
= kind:module_kind() "{" _ configs:init_config()* _ fn_decls:fn_decl()* "}" _ | |||
= kind:module_kind() "{" _ configs:init_config()* _ global_consts:global_const()* _ fn_decls:fn_decl()* "}" _ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we start mixing the terms "global variables/vars" and "global constants/const" it `will become very confusing 😄
The proposal is to stay consistent and use the term "global variable" everywhere including here in the parse. Thus, to rename:
global_consts
->global_vars
global_const
->global_var
IrAstGlobalConst
->IrAstGlobalVar
build_global_consts_map
->build_global_vars_map
sway-ir/src/parser.rs
Outdated
@@ -982,6 +1010,7 @@ mod ir_builder { | |||
let mut builder = IrBuilder { | |||
module, | |||
configs_map: build_configs_map(&mut ctx, &module, ir_ast_mod.configs, &md_map), | |||
global_map: build_global_consts_map(&mut ctx, &module, ir_ast_mod.global_consts), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
global_map: build_global_consts_map(&mut ctx, &module, ir_ast_mod.global_consts), | |
globals_map: build_global_vars_map(&mut ctx, &module, ir_ast_mod.global_vars), |
sway-ir/src/parser.rs
Outdated
@@ -998,6 +1027,7 @@ mod ir_builder { | |||
struct IrBuilder { | |||
module: Module, | |||
configs_map: BTreeMap<String, String>, | |||
global_map: BTreeMap<Vec<String>, GlobalVar>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global_map: BTreeMap<Vec<String>, GlobalVar>, | |
globals_map: BTreeMap<Vec<String>, GlobalVar>, |
…to vaivaswatha/ir_consts_2
…to vaivaswatha/ir_consts_2
@ironcev I've addressed your comments. |
2nd Step as part of #6351, in continuation to #6896