Skip to content

Commit

Permalink
Merge branch 'master' into kayagokalp/deploy-default-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel authored Jul 24, 2024
2 parents 6e9958f + 5085545 commit 1184d61
Show file tree
Hide file tree
Showing 61 changed files with 1,619 additions and 508 deletions.
33 changes: 14 additions & 19 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,18 +1601,19 @@ pub fn dependency_namespace(
) -> Result<namespace::Root, vec1::Vec1<CompileError>> {
// TODO: Clean this up when config-time constants v1 are removed.
let node_idx = &graph[node];
let name = Some(Ident::new_no_span(node_idx.name.clone()));
let name = Ident::new_no_span(node_idx.name.clone());
let mut root_module = if let Some(contract_id_value) = contract_id_value {
namespace::default_with_contract_id(engines, name.clone(), contract_id_value, experimental)?
namespace::default_with_contract_id(
engines,
name.clone(),
Visibility::Public,
contract_id_value,
experimental,
)?
} else {
namespace::Module::default()
namespace::Module::new(name, Visibility::Public, None)
};

root_module.write(engines, |root_module| {
root_module.name.clone_from(&name);
root_module.visibility = Visibility::Public;
});

// Add direct dependencies.
let mut core_added = false;
for edge in graph.edges_directed(node, Direction::Outgoing) {
Expand All @@ -1634,16 +1635,14 @@ pub fn dependency_namespace(
// Construct namespace with contract id
let contract_id_value = format!("0x{dep_contract_id}");
let node_idx = &graph[dep_node];
let name = Some(Ident::new_no_span(node_idx.name.clone()));
let mut module = namespace::default_with_contract_id(
let name = Ident::new_no_span(node_idx.name.clone());
namespace::default_with_contract_id(
engines,
name.clone(),
Visibility::Private,
contract_id_value,
experimental,
)?;
module.name = name;
module.visibility = Visibility::Public;
module
)?
}
};
dep_namespace.is_external = true;
Expand Down Expand Up @@ -2481,9 +2480,6 @@ pub fn build(
}

if let TreeType::Library = compiled.tree_type {
compiled.root_module.write(&engines, |root_module| {
root_module.name = Some(Ident::new_no_span(pkg.name.clone()));
});
lib_namespace_map.insert(node, compiled.root_module);
}
source_map.insert_dependency(descriptor.manifest_file.dir());
Expand Down Expand Up @@ -2737,8 +2733,7 @@ pub fn check(
.namespace
.program_id(engines)
.read(engines, |m| m.clone());
module.name = Some(Ident::new_no_span(pkg.name.clone()));
module.span = Some(
module.set_span(
Span::new(
manifest.entry_string()?,
0,
Expand Down
5 changes: 2 additions & 3 deletions sway-core/src/abi_generation/abi_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sway_types::integer_bits::IntegerBits;
use crate::{language::CallPath, Engines, TypeArgument, TypeId, TypeInfo};

pub struct AbiStrContext {
pub program_name: Option<String>,
pub program_name: String,
pub abi_with_callpaths: bool,
pub abi_with_fully_specified_types: bool,
}
Expand Down Expand Up @@ -182,9 +182,8 @@ fn call_path_display(ctx: &AbiStrContext, call_path: &CallPath) -> String {
return call_path.suffix.as_str().to_string();
}
let mut buf = String::new();
let root_name = ctx.program_name.as_deref();
for (index, prefix) in call_path.prefixes.iter().enumerate() {
if index == 0 && Some(prefix.as_str()) == root_name {
if index == 0 && prefix.as_str() == ctx.program_name {
continue;
}
buf.push_str(prefix.as_str());
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> AbiContext<'a> {
.root
.namespace
.program_id(engines)
.read(engines, |m| m.name.clone().map(|v| v.as_str().to_string())),
.read(engines, |m| m.name().to_string()),
abi_with_callpaths: self.abi_with_callpaths,
abi_with_fully_specified_types,
}
Expand Down
11 changes: 5 additions & 6 deletions sway-core/src/ir_generation/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,12 +1316,11 @@ mod tests {
},
);
let mut md_mgr = MetadataManager::default();
let mut core_lib = namespace::Root::from(namespace::Module {
name: Some(sway_types::Ident::new_no_span(
"assert_is_constant_test".to_string(),
)),
..Default::default()
});
let mut core_lib = namespace::Root::from(namespace::Module::new(
sway_types::Ident::new_no_span("assert_is_constant_test".to_string()),
crate::Visibility::Private,
None,
));

let r = crate::compile_to_ast(
&handler,
Expand Down
15 changes: 5 additions & 10 deletions sway-core/src/language/call_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ impl CallPath {
/// before the identifier is added to the environment.
pub fn ident_to_fullpath(suffix: Ident, namespace: &Namespace) -> CallPath {
let mut res: Self = suffix.clone().into();
if let Some(ref pkg_name) = namespace.root_module().name {
res.prefixes.push(pkg_name.clone())
};
res.prefixes.push(namespace.root_module().name().clone());
for mod_path in namespace.mod_path() {
res.prefixes.push(mod_path.clone())
}
Expand Down Expand Up @@ -404,9 +402,7 @@ impl CallPath {
let mut prefixes: Vec<Ident> = vec![];

if !is_external {
if let Some(pkg_name) = &namespace.root_module().name {
prefixes.push(pkg_name.clone());
}
prefixes.push(namespace.root_module().name().clone());

if !is_absolute {
for mod_path in namespace.mod_path() {
Expand Down Expand Up @@ -439,9 +435,8 @@ impl CallPath {
}
} else {
let mut prefixes: Vec<Ident> = vec![];
if let Some(pkg_name) = &namespace.root_module().read(engines, |m| m.name.clone()) {
prefixes.push(pkg_name.clone());
}
prefixes.push(namespace.root_module().name().clone());

for mod_path in namespace.mod_path() {
prefixes.push(mod_path.clone());
}
Expand Down Expand Up @@ -473,7 +468,7 @@ impl CallPath {
let converted = self.to_fullpath(engines, namespace);

if let Some(first) = converted.prefixes.first() {
if namespace.root_module().read(engines, |m| m.name.clone()) == Some(first.clone()) {
if namespace.root_module().name() == first {
return converted.lshift();
}
}
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/language/ty/expression/intrinsic_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl CollectTypesMetadata for TyIntrinsicFunctionKind {
types_metadata.push(TypeMetadata::LoggedType(
LogId::new(logged_type.get_abi_type_str(
&AbiStrContext {
program_name: Some(ctx.program_name.clone()),
program_name: ctx.program_name.clone(),
abi_with_callpaths: true,
abi_with_fully_specified_types: true,
},
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/language/ty/expression/scrutinee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub enum TyScrutineeVariant {
Literal(Literal),
Variable(Ident),
Constant(Ident, Literal, TyConstantDecl),
Configurable(Ident, Literal, TyConfigurableDecl),
StructScrutinee {
struct_ref: DeclRefStruct,
fields: Vec<TyStructScrutineeField>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ where
engines: &Engines,
decl: &TyDecl,
) -> Option<(Option<TyAstNode>, Option<TyAstNode>)> {
if matches!(self.ctx.namespace.root().module.read(engines, |m| m.name.clone()).as_ref(), Some(x) if x.as_str() == "core")
{
if self.ctx.namespace.root().module.name().as_str() == "core" {
return Some((None, None));
}

Expand Down Expand Up @@ -437,8 +436,7 @@ where
engines: &Engines,
decl: &TyDecl,
) -> Option<(Option<TyAstNode>, Option<TyAstNode>)> {
if matches!(self.ctx.namespace.root().module.read(engines, |m| m.name.clone()).as_ref(), Some(x) if x.as_str() == "core")
{
if self.ctx.namespace.root().module.name().as_str() == "core" {
return Some((None, None));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ pub(crate) fn collect_duplicate_match_pattern_variables(
ty::TyScrutineeVariant::Variable(ident) => add_variable(left_most_branch, ident, false),
ty::TyScrutineeVariant::Literal(_) => (),
ty::TyScrutineeVariant::Constant { .. } => (),
ty::TyScrutineeVariant::Configurable { .. } => (),
ty::TyScrutineeVariant::StructScrutinee { fields, .. } => {
// If a field does not have a scrutinee, the field itself is a variable.
for field in fields {
Expand Down Expand Up @@ -247,3 +246,49 @@ pub(crate) fn collect_duplicate_match_pattern_variables(
}
}
}

/// Returns [Ident]s for all match arm variables found in the `scrutinee`,
/// together with the information if the variable is a struct field (true)
/// or not (false), or empty [Vec] if there are no variables declared in
/// the `scrutinee`.
///
/// If the `scrutinee` contains alternatives, and thus a variable is declared
/// multiple times, each occurrence of the variable will be returned.
pub(crate) fn collect_match_pattern_variables(scrutinee: &TyScrutinee) -> Vec<(Ident, bool)> {
let mut variables = vec![];

recursively_collect_variables(&mut variables, scrutinee);

return variables;

fn recursively_collect_variables(variables: &mut Vec<(Ident, bool)>, scrutinee: &TyScrutinee) {
match &scrutinee.variant {
ty::TyScrutineeVariant::CatchAll => (),
ty::TyScrutineeVariant::Variable(ident) => variables.push((ident.clone(), false)),
ty::TyScrutineeVariant::Literal(_) => (),
ty::TyScrutineeVariant::Constant { .. } => (),
ty::TyScrutineeVariant::StructScrutinee { fields, .. } => {
// If a field does not have a scrutinee, the field itself is a variable.
for field in fields {
match &field.scrutinee {
Some(scrutinee) => recursively_collect_variables(variables, scrutinee),
None => variables.push((field.field.clone(), true)),
}
}
}
ty::TyScrutineeVariant::Or(scrutinees) => {
for scrutinee in scrutinees {
recursively_collect_variables(variables, scrutinee);
}
}
ty::TyScrutineeVariant::Tuple(scrutinees) => {
for scrutinee in scrutinees {
recursively_collect_variables(variables, scrutinee);
}
}
ty::TyScrutineeVariant::EnumScrutinee { value, .. } => {
recursively_collect_variables(variables, value)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod constructor_factory;
mod duplicates;
mod match_pattern_variables;
mod matrix;
mod patstack;
mod pattern;
Expand All @@ -8,6 +8,8 @@ mod reachable_report;
mod usefulness;
mod witness_report;

pub(crate) use duplicates::collect_duplicate_match_pattern_variables;
pub(crate) use match_pattern_variables::{
collect_duplicate_match_pattern_variables, collect_match_pattern_variables,
};
pub(in crate::semantic_analysis::ast_node::expression) use reachable_report::ReachableReport;
pub(crate) use usefulness::check_match_expression_usefulness;
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ impl Pattern {
ty::TyScrutineeVariant::Variable(_) => Pattern::Wildcard,
ty::TyScrutineeVariant::Literal(value) => Pattern::from_literal(value),
ty::TyScrutineeVariant::Constant(_, value, _) => Pattern::from_literal(value),
ty::TyScrutineeVariant::Configurable(_, value, _) => Pattern::from_literal(value),
ty::TyScrutineeVariant::StructScrutinee {
struct_ref,
fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use indexmap::IndexMap;

use crate::{
language::{
ty::{self, TyConfigurableDecl, TyConstantDecl},
ty::{self, TyConstantDecl},
CallPath, Literal,
},
semantic_analysis::{
Expand Down Expand Up @@ -229,9 +229,6 @@ pub(super) fn matcher(
ty::TyScrutineeVariant::Constant(_, _, const_decl) => {
Ok(match_constant(ctx, exp, const_decl, span))
}
ty::TyScrutineeVariant::Configurable(_, _, config_decl) => {
Ok(match_configurable(ctx, exp, config_decl, span))
}
ty::TyScrutineeVariant::StructScrutinee {
struct_ref: _,
fields,
Expand Down Expand Up @@ -422,31 +419,6 @@ fn match_constant(
ReqDeclTree::req(req)
}

fn match_configurable(
ctx: TypeCheckContext,
exp: &ty::TyExpression,
decl: TyConfigurableDecl,
span: Span,
) -> ReqDeclTree {
let name = decl.name().clone();
let return_type = decl.type_ascription.type_id;

let req = (
exp.to_owned(),
ty::TyExpression {
expression: ty::TyExpressionVariant::ConfigurableExpression {
span: span.clone(),
decl: Box::new(decl),
call_path: Some(CallPath::from(name).to_fullpath(ctx.engines(), ctx.namespace())),
},
return_type,
span,
},
);

ReqDeclTree::req(req)
}

fn match_struct(
handler: &Handler,
mut ctx: TypeCheckContext,
Expand Down
Loading

0 comments on commit 1184d61

Please sign in to comment.