Skip to content
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
44 changes: 22 additions & 22 deletions crates/codegen/tests/fixtures/sonatina_ir/effect_ptr_domains.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func inline(always) private %alloc_bytes(v0.i256) -> i256 {
return v11;
}

func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_43dd(noalias nocapture v0.objref<@layout_0>) {
func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_5804(noalias nocapture v0.objref<@layout_0>) {
block0:
jump block1;

Expand Down Expand Up @@ -70,12 +70,12 @@ func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_43d
return;
}

func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_7060(v0.i256) {
func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_b71c(v0.i256) {
block0:
jump block1;

block1:
v2.i256 = evm_sload v0;
v2.i256 = mload v0 i256;
(v4.i256, v5.i1) = uaddo v2 1.i256;
br v5 block2 block3;

Expand All @@ -85,24 +85,24 @@ func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_706
evm_revert 0.i256 36.i256;

block3:
evm_sstore v0 v4;
v12.i256 = add v0 1.i256;
v13.i256 = evm_sload v12;
(v15.i256, v16.i1) = uaddo v13 2.i256;
br v16 block2 block4;
mstore v0 v4 i256;
v13.i256 = add v0 32.i256;
v14.i256 = mload v13 i256;
(v16.i256, v17.i1) = uaddo v14 2.i256;
br v17 block2 block4;

block4:
v18.i256 = add v0 1.i256;
evm_sstore v18 v15;
v19.i256 = add v0 32.i256;
mstore v19 v16 i256;
return;
}

func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_e8c4(v0.i256) {
func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_f565(v0.i256) {
block0:
jump block1;

block1:
v2.i256 = mload v0 i256;
v2.i256 = evm_sload v0;
(v4.i256, v5.i1) = uaddo v2 1.i256;
br v5 block2 block3;

Expand All @@ -112,15 +112,15 @@ func private %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_e8c
evm_revert 0.i256 36.i256;

block3:
mstore v0 v4 i256;
v13.i256 = add v0 32.i256;
v14.i256 = mload v13 i256;
(v16.i256, v17.i1) = uaddo v14 2.i256;
br v17 block2 block4;
evm_sstore v0 v4;
v12.i256 = add v0 1.i256;
v13.i256 = evm_sload v12;
(v15.i256, v16.i1) = uaddo v13 2.i256;
br v16 block2 block4;

block4:
v19.i256 = add v0 32.i256;
mstore v19 v16 i256;
v18.i256 = add v0 1.i256;
evm_sstore v18 v15;
return;
}

Expand All @@ -139,13 +139,13 @@ func private %main() {

block1:
v1.i256 = call %alloc;
call %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_e8c4 v1;
call %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_7060 0.i256;
call %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_b71c v1;
call %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_f565 0.i256;
v7.constref<@layout_0> = const.ref $const_region_0;
v8.constref<@layout_0> = const.ref $const_region_0;
v9.@layout_0 = const.load v8;
obj.store v0 v9;
call %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_43dd v0;
call %standalone_effect_ptr_domains__effect_ptr_domains__bump__gb2d8_5804 v0;
return;
}

Expand Down
8 changes: 4 additions & 4 deletions crates/codegen/tests/fixtures/sonatina_ir/erc20.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func private %__CoolCoin_init(v0.i256, v1.@layout_0, v2.i256, v3.i256) {
br v12 block2 block3;

block2:
call %standalone_erc20__erc20__mint__g5a03_041c v1 v0 v2;
call %standalone_erc20__erc20__mint__g5a03_f73b v1 v0 v2;
jump block4;

block3:
Expand Down Expand Up @@ -132,7 +132,7 @@ func private %__CoolCoin_recv_1_0(v0.@layout_0, v1.i256, v2.i256, v3.i256) -> i1

block1:
call %require v3 1.i256;
call %standalone_erc20__erc20__mint__g5a03_6577 v0 v1 v2;
call %standalone_erc20__erc20__mint__g5a03_4ef7 v0 v1 v2;
return 1.i1;
}

Expand Down Expand Up @@ -3365,7 +3365,7 @@ func inline(always) private %mapping_slot__g7bf4(v0.i256, v1.@layout_8) -> i256
jump block3;
}

func private %standalone_erc20__erc20__mint__g5a03_041c(v0.@layout_0, v1.i256, v2.i256) {
func private %standalone_erc20__erc20__mint__g5a03_4ef7(v0.@layout_0, v1.i256, v2.i256) {
block0:
jump block1;

Expand Down Expand Up @@ -3410,7 +3410,7 @@ func private %standalone_erc20__erc20__mint__g5a03_041c(v0.@layout_0, v1.i256, v
return;
}

func private %standalone_erc20__erc20__mint__g5a03_6577(v0.@layout_0, v1.i256, v2.i256) {
func private %standalone_erc20__erc20__mint__g5a03_f73b(v0.@layout_0, v1.i256, v2.i256) {
block0:
jump block1;

Expand Down
36 changes: 18 additions & 18 deletions crates/codegen/tests/fixtures/sonatina_ir/erc20_low_level.snap
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,26 @@ func inline(always) private %core__lib__ptr__alloc_bytes_8b3e(v0.i256) -> i256 {
return v11;
}

func private %allowance__g7ab3(v0.@layout_0, v1.@layout_0, v2.i256) -> i256 {
func private %impl_Erc20__allowance(v0.i256, v1.@layout_0, v2.@layout_0) -> i256 {
block0:
jump block1;

block1:
v7.@layout_2 = insert_value undef.@layout_2 0.i256 v0;
v9.@layout_2 = insert_value v7 1.i256 v1;
v11.i256 = add v2 1.i256;
v7.@layout_2 = insert_value undef.@layout_2 0.i256 v1;
v9.@layout_2 = insert_value v7 1.i256 v2;
v11.i256 = add v0 1.i256;
v12.i256 = call %get__g4007 v11 v9;
return v12;
}

func private %impl_Erc20__allowance(v0.i256, v1.@layout_0, v2.@layout_0) -> i256 {
func private %allowance__g7ab3(v0.@layout_0, v1.@layout_0, v2.i256) -> i256 {
block0:
jump block1;

block1:
v7.@layout_2 = insert_value undef.@layout_2 0.i256 v1;
v9.@layout_2 = insert_value v7 1.i256 v2;
v11.i256 = add v0 1.i256;
v7.@layout_2 = insert_value undef.@layout_2 0.i256 v0;
v9.@layout_2 = insert_value v7 1.i256 v1;
v11.i256 = add v2 1.i256;
v12.i256 = call %get__g4007 v11 v9;
return v12;
}
Expand Down Expand Up @@ -1274,6 +1274,16 @@ func private %impl_Erc20__transfer(v0.i256, v1.@layout_0, v2.@layout_0, v3.i256)
return;
}

func private %transfer_from__g5bd7(v0.@layout_0, v1.@layout_0, v2.i256, v3.i256) -> i256 {
block0:
jump block1;

block1:
v4.@layout_0 = call %caller;
call %impl_Erc20__transfer_from v3 v4 v0 v1 v2;
return 1.i256;
}

func private %impl_Erc20__transfer_from(v0.i256, v1.@layout_0, v2.@layout_0, v3.@layout_0, v4.i256) {
block0:
jump block1;
Expand Down Expand Up @@ -1308,16 +1318,6 @@ func private %impl_Erc20__transfer_from(v0.i256, v1.@layout_0, v2.@layout_0, v3.
return;
}

func private %transfer_from__g5bd7(v0.@layout_0, v1.@layout_0, v2.i256, v3.i256) -> i256 {
block0:
jump block1;

block1:
v4.@layout_0 = call %caller;
call %impl_Erc20__transfer_from v3 v4 v0 v1 v2;
return 1.i256;
}

func inline(always) private %impl_trait_u256__write_key(v0.i256, v1.i256) {
block0:
jump block1;
Expand Down
8 changes: 4 additions & 4 deletions crates/hir/src/analysis/semantic/access/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use crate::{
provider::{AddressSpace, provider_semantics},
shape::Shape,
trait_resolution::PredicateListId,
ty_check::{BindingAccess, BodyOwner, LocalBinding, infer_body},
ty_check::{BindingAccess, BodyOwner, EffectArg, LocalBinding, infer_body},
ty_def::{BorrowKind, CapabilityKind, ShapeMode, TyData, TyId},
ty_is_copy, ty_is_snapshot,
},
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<'a, 'db> Analysis<'a, 'db> {
site: site.slot_site(self.db, idx as u32),
requirement_idx: idx as u32,
},
provider_semantics(self.db, value.ty).address_space,
Some(provider_semantics(self.db, value.ty).address_space),
idx as u32,
)),
_ => None,
Expand Down Expand Up @@ -2923,11 +2923,11 @@ impl<'a, 'db> Analysis<'a, 'db> {
&& let Some(Some(site)) = self.instance.call_sites(self.db).get(expr.index())
{
for ((effect, _), name) in effects.iter().zip([&lhs, &rhs]) {
if let Some(source) = site
if let Some(EffectArg::With(source)) = site
.effect_args
.iter()
.find(|arg| arg.binding_idx == effect.binding_idx)
.and_then(|arg| arg.with_source)
.map(|arg| arg.arg)
{
diag.push_secondary(
format!("{name} is provided here"),
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/src/analysis/semantic/access/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'db> Domains<'db> {
pub fn provider(&mut self, binding: &ProviderBinding<'db>) -> u32 {
self.intern(
Some(binding.source.clone()),
binding.semantics.address_space,
Some(binding.semantics.address_space),
Some(binding.provider_idx),
)
}
Expand Down
7 changes: 0 additions & 7 deletions crates/hir/src/analysis/semantic/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ pub(crate) fn normalized_body_error_to_diag<'db>(
),
SemanticDiagnosticSpan::LocalSourceOrBody { instance, local },
),
NormalizeError::MissingProviderAddressSpace(provider) => (
format!("normalized provider has no address space: {provider:?}"),
SemanticDiagnosticSpan::Origin {
owner,
origin: SemOrigin::Body(owner),
},
),
NormalizeError::UnresolvedCapabilityConst(ty) => (
format!(
"constant holding a capability has no resolved value: {}",
Expand Down
11 changes: 4 additions & 7 deletions crates/hir/src/analysis/semantic/instance/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ pub(crate) enum SemanticBodyAdmissionError<'db> {
pub struct CallEffectArg<'db> {
pub binding_idx: u32,
pub arg: EffectArg<'db>,
pub with_source: Option<ExprId>,
pub required_mut: bool,
pub instantiated_key_ty: Option<TyId<'db>>,
pub provider_target_ty: Option<TyId<'db>>,
Expand All @@ -199,8 +198,7 @@ impl<'db> CallEffectArg<'db> {
fn new(binding_idx: u32, arg: &ResolvedEffectArg<'db>) -> Self {
Self {
binding_idx,
arg: arg.arg.clone(),
with_source: arg.with_source,
arg: arg.arg,
required_mut: arg.required_mut,
instantiated_key_ty: arg.instantiated_key_ty,
provider_target_ty: arg.provider_target_ty,
Expand Down Expand Up @@ -601,11 +599,10 @@ fn instance_effect_args<'db>(
expanded.push(CallEffectArg {
binding_idx: target,
arg: EffectArg::Binding(binding),
with_source: None,
required_mut: callee.requirement.is_mut,
instantiated_key_ty: callee.requirement.key.key_ty(),
provider_target_ty: provider.semantics.target_ty,
provider: provider.semantics.address_space,
provider: Some(provider.semantics.address_space),
});
providers.push(EffectProviderSpecialization {
provider: ProviderBinding {
Expand Down Expand Up @@ -2296,7 +2293,7 @@ fn provisional_provider_binding_for_effect<'db>(
semantics: crate::analysis::ty::provider::ProviderSemantics {
provider_ty,
kind: ProviderKind::Place,
address_space: Some(field.address_space),
address_space: field.address_space,
target_ty: Some(provider_ty),
},
});
Expand Down Expand Up @@ -2982,7 +2979,7 @@ fn instantiate_provider_binding<'db>(
db,
provider_ty,
target_ty,
provider.semantics.address_space,
Some(provider.semantics.address_space),
)
};
Ok(ProviderBinding {
Expand Down
54 changes: 24 additions & 30 deletions crates/hir/src/analysis/semantic/lower/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,15 @@ impl<'a, 'db> SmirLowerCtxt<'a, 'db> {
}

fn effect_arg_provider_space(&self, arg: &CallEffectArg<'db>) -> Option<AddressSpace> {
arg.provider.or_else(|| match &arg.arg {
EffectArg::Place(place) => {
let PlaceBase::Binding(binding) = place.base;
self.binding_provider(binding)
.and_then(|provider| provider.semantics.address_space)
}
EffectArg::Binding(binding) => self
.binding_provider(*binding)
.and_then(|provider| provider.semantics.address_space),
EffectArg::Value(_) => None,
arg.provider.or_else(|| {
let binding = match arg.arg {
EffectArg::With(value) => {
let PlaceBase::Binding(binding) = self.typed_body.expr_place(value)?.base;
binding
}
EffectArg::Binding(binding) => binding,
};
Some(self.binding_provider(binding)?.semantics.address_space)
})
}

Expand All @@ -106,30 +105,25 @@ impl<'a, 'db> SmirLowerCtxt<'a, 'db> {
}

fn lower_effect_arg(&mut self, arg: &CallEffectArg<'db>) -> SEffectArg<'db> {
let source = arg.with_source.map(|expr| {
self.with_binding_sources
.get(&expr)
let place = match arg.arg {
EffectArg::With(value) => match self
.with_binding_sources
.get(&value)
.expect("effect provider should be captured by its with binding")
.clone()
});
let place = match source {
Some(WithBindingSource::Place(place)) => place,
Some(WithBindingSource::Temporary(local)) => {
// Only owned temporaries acquire mutability from their uses. Read-only
// providers can remain const-backed, and captured places keep their access.
if arg.required_mut {
self.locals[local.index()].mutability = Mutability::Mutable;
}
SPlace::new(local)
}
None => match &arg.arg {
EffectArg::Place(place) => self.lower_place_data(place),
// The caller's own provider, passed on.
EffectArg::Binding(binding) => SPlace::new(self.alloc_binding_local(*binding)),
EffectArg::Value(_) => {
unreachable!("a `with` value is captured where its block is entered")
{
WithBindingSource::Place(place) => place,
WithBindingSource::Temporary(local) => {
// Only owned temporaries acquire mutability from their uses. Read-only
// providers can remain const-backed, and captured places keep their access.
if arg.required_mut {
self.locals[local.index()].mutability = Mutability::Mutable;
}
SPlace::new(local)
}
},
// The caller's own provider, passed on.
EffectArg::Binding(binding) => SPlace::new(self.alloc_binding_local(binding)),
};
SEffectArg {
binding_idx: arg.binding_idx,
Expand Down
4 changes: 0 additions & 4 deletions crates/hir/src/analysis/semantic/lower/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ impl<'a, 'db> SmirLowerCtxt<'a, 'db> {
}
}

pub(super) fn lower_place_data(&mut self, source_place: &Place<'db>) -> SPlace<'db> {
self.lower_place_source(source_place, false)
}

fn lower_place_source(&mut self, source_place: &Place<'db>, capture: bool) -> SPlace<'db> {
let PlaceBase::Binding(binding) = source_place.base;
let (mut place, mut ty) = match self.capture_places.get(&binding) {
Expand Down
Loading
Loading