Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

Commit bb87a88

Browse files
authored
support pub attribute (#263)
* support pub attribute for struct fields
1 parent 4596f2b commit bb87a88

22 files changed

Lines changed: 153 additions & 44 deletions

File tree

examples/assignment.no

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Thing {
2-
xx: Field,
2+
pub xx: Field,
33
}
44

55
fn try_to_mutate(thing: Thing) {

examples/hint.no

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct Thing {
2-
xx: Field,
3-
yy: Field,
2+
pub xx: Field,
3+
pub yy: Field,
44
}
55

66
hint fn mul(lhs: Field, rhs: Field) -> Field {

examples/types.no

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct Thing {
2-
xx: Field,
3-
yy: Field,
2+
pub xx: Field,
3+
pub yy: Field,
44
}
55

66
fn main(pub xx: Field, pub yy: Field) {

examples/types_array.no

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct Thing {
2-
xx: Field,
3-
yy: Field,
2+
pub xx: Field,
3+
pub yy: Field,
44
}
55

66
fn main(pub xx: Field, pub yy: Field) {

examples/types_array_output.no

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct Thing {
2-
xx: Field,
3-
yy: Field,
2+
pub xx: Field,
3+
pub yy: Field,
44
}
55

66
fn main(pub xx: Field, pub yy: Field) -> [Thing; 2] {

src/circuit_writer/ir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ impl<B: Backend> IRWriter<B> {
706706
// find range of field
707707
let mut start = 0;
708708
let mut len = 0;
709-
for (field, field_typ) in &struct_info.fields {
709+
for (field, field_typ, _attribute) in &struct_info.fields {
710710
if field == &rhs.value {
711711
len = self.size_of(field_typ);
712712
break;

src/circuit_writer/writer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<B: Backend> CircuitWriter<B> {
320320
.clone();
321321

322322
let mut offset = 0;
323-
for (_field_name, field_typ) in &struct_info.fields {
323+
for (_field_name, field_typ, _attribute) in &struct_info.fields {
324324
let len = self.size_of(field_typ);
325325
let range = offset..(offset + len);
326326
self.constrain_inputs_to_main(&input[range], field_typ, span)?;
@@ -501,7 +501,7 @@ impl<B: Backend> CircuitWriter<B> {
501501
// find range of field
502502
let mut start = 0;
503503
let mut len = 0;
504-
for (field, field_typ) in &struct_info.fields {
504+
for (field, field_typ, _attribute) in &struct_info.fields {
505505
if field == &rhs.value {
506506
len = self.size_of(field_typ);
507507
break;

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ pub enum ErrorKind {
372372
#[error("division by zero")]
373373
DivisionByZero,
374374

375+
#[error("cannot access private field `{1}` of struct `{0}` from outside its methods.")]
376+
PrivateFieldAccess(String, String),
377+
375378
#[error("lhs `{0}` is less than rhs `{1}`")]
376379
NegativeLhsLessThanRhs(String, String),
377380

src/inputs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<B: Backend> CompiledCircuit<B> {
141141

142142
// parse each field
143143
let mut res = vec![];
144-
for (field_name, field_ty) in fields {
144+
for (field_name, field_ty, _attribute) in fields {
145145
let value = map.remove(field_name).ok_or_else(|| {
146146
ParsingError::MissingStructFieldIdent(field_name.to_string())
147147
})?;

src/mast/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl<B: Backend> Mast<B> {
463463

464464
let mut sum = 0;
465465

466-
for (_, t) in &struct_info.fields {
466+
for (_, t, _) in &struct_info.fields {
467467
sum += self.size_of(t);
468468
}
469469

@@ -567,8 +567,8 @@ fn monomorphize_expr<B: Backend>(
567567
let typ = struct_info
568568
.fields
569569
.iter()
570-
.find(|(name, _)| name == &rhs.value)
571-
.map(|(_, typ)| typ.clone());
570+
.find(|(name, _, _)| name == &rhs.value)
571+
.map(|(_, typ, _)| typ.clone());
572572

573573
let mexpr = expr.to_mast(
574574
ctx,

0 commit comments

Comments
 (0)