Fixing Changes
This commit is contained in:
parent
1760579dea
commit
dcd6ff6a93
|
@ -1,32 +0,0 @@
|
|||
from min_artiq import *
|
||||
from numpy import int32
|
||||
|
||||
@nac3
|
||||
class DemoTest:
|
||||
ATTR1: KernelInvariant[int32] = 16 # Kernel Access
|
||||
ATTR2: int32 = 16 # Host only
|
||||
|
||||
|
||||
@nac3
|
||||
class Demo:
|
||||
core: KernelInvariant[Core]
|
||||
ATTR3: int32 = 16 # Host only
|
||||
ATTR4: KernelInvariant[int32] = 16 # Kernel Access
|
||||
|
||||
def __init__(self):
|
||||
self.core = Core()
|
||||
|
||||
@kernel
|
||||
def run(self):
|
||||
# Should Work
|
||||
print_int32(self.ATTR4)
|
||||
#print_int32(Demo.ATTR4)
|
||||
#print_int32(DemoTest.ATTR1)
|
||||
|
||||
# Should NOT Work
|
||||
#print_int32(self.ATTR3)
|
||||
#print_int32(DemoTest.ATTR2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Demo().run()
|
|
@ -87,7 +87,6 @@ pub fn get_exn_constructor(
|
|||
object_id: DefinitionId(class_id),
|
||||
type_vars: Vec::default(),
|
||||
fields: exception_fields,
|
||||
attr: Vec::default(),
|
||||
methods: vec![("__init__".into(), signature, DefinitionId(cons_id))],
|
||||
ancestors: vec![
|
||||
TypeAnnotation::CustomClass { id: DefinitionId(class_id), params: Vec::default() },
|
||||
|
@ -445,7 +444,6 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
|||
object_id: PRIMITIVE_DEF_IDS.exception,
|
||||
type_vars: Vec::default(),
|
||||
fields: exception_fields,
|
||||
attr: Vec::default(),
|
||||
methods: Vec::default(),
|
||||
ancestors: vec![],
|
||||
constructor: None,
|
||||
|
@ -472,7 +470,6 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
|||
object_id: PRIMITIVE_DEF_IDS.option,
|
||||
type_vars: vec![option_ty_var],
|
||||
fields: vec![],
|
||||
attr: Vec::default(),
|
||||
methods: vec![
|
||||
("is_some".into(), is_some_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.option.0 + 1)),
|
||||
("is_none".into(), is_some_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.option.0 + 2)),
|
||||
|
@ -563,7 +560,6 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
|||
object_id: PRIMITIVE_DEF_IDS.ndarray,
|
||||
type_vars: vec![ndarray_dtype_ty, ndarray_ndims_ty],
|
||||
fields: Vec::default(),
|
||||
attr: Vec::default(),
|
||||
methods: vec![
|
||||
("copy".into(), ndarray_copy_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.ndarray.0 + 1)),
|
||||
("fill".into(), ndarray_fill_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.ndarray.0 + 2)),
|
||||
|
|
|
@ -1051,7 +1051,6 @@ impl TopLevelComposer {
|
|||
object_id,
|
||||
ancestors,
|
||||
fields,
|
||||
attr,
|
||||
methods,
|
||||
resolver,
|
||||
type_vars,
|
||||
|
@ -1070,11 +1069,10 @@ impl TopLevelComposer {
|
|||
class_body_ast,
|
||||
_class_ancestor_def,
|
||||
class_fields_def,
|
||||
class_attr_def,
|
||||
class_methods_def,
|
||||
class_type_vars_def,
|
||||
class_resolver,
|
||||
) = (*object_id, *name, bases, body, ancestors, fields, attr, methods, type_vars, resolver);
|
||||
) = (*object_id, *name, bases, body, ancestors, fields, methods, type_vars, resolver);
|
||||
|
||||
let class_resolver = class_resolver.as_ref().unwrap();
|
||||
let class_resolver = class_resolver.as_ref();
|
||||
|
@ -1354,99 +1352,6 @@ impl TopLevelComposer {
|
|||
]))
|
||||
}
|
||||
}
|
||||
ast::StmtKind::AnnAssign { target, annotation, value: Some(boxed_expr), .. } => {
|
||||
// Class attributes are set as immutable regardless
|
||||
// Check if Kernel or KernelInvariant to allow access in Kernel
|
||||
if let ast::ExprKind::Name {id: attr, .. } = &target.node {
|
||||
if defined_fields.insert(attr.to_string()){
|
||||
let (annotation, mutable) = match &annotation.node {
|
||||
ast::ExprKind::Subscript { slice, .. } => (slice, false),
|
||||
_ if core_config.kernel_ann.is_none() => (annotation, false),
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
let field_type;
|
||||
match &**boxed_expr {
|
||||
ast::Located {location: _, custom: _, node: ExprKind::Constant { value: v, kind: _ }} => {
|
||||
match v {
|
||||
// Constant::Bool(i) => {field_type = unifier.get_fresh_literal(vec![SymbolValue::Bool(*i)], std::option::Option::Some(*loc));}
|
||||
// Constant::Str(i) => {field_type = unifier.get_fresh_literal(vec![SymbolValue::Str(i.to_string())], std::option::Option::Some(*loc));}
|
||||
// Constant::Int(i) => {field_type = unifier.get_fresh_literal(vec![SymbolValue::I64((*i).try_into().unwrap())], std::option::Option::Some(*loc));}
|
||||
// Constant::Float(i) => {field_type = unifier.get_fresh_literal(vec![SymbolValue::Double(*i)], std::option::Option::Some(*loc));}
|
||||
// _ => {println!("Unknown type"); field_type = unifier.get_dummy_var().0}
|
||||
Constant::Bool(_) => {field_type = unifier.get_dummy_var().0;}
|
||||
Constant::Str(_) => {field_type = unifier.get_dummy_var().0;}
|
||||
Constant::Int(_) => {field_type = unifier.get_dummy_var().0;}
|
||||
Constant::Float(_) => {field_type = unifier.get_dummy_var().0;}
|
||||
_ => {
|
||||
return Err(HashSet::from([
|
||||
format!(
|
||||
"unsupported statement in class definition body (at {})",
|
||||
b.location
|
||||
),
|
||||
]))
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(HashSet::from([
|
||||
format!(
|
||||
"unsupported statement in class definition body (at {})",
|
||||
b.location
|
||||
),
|
||||
]))
|
||||
}
|
||||
}
|
||||
|
||||
class_attr_def.push((*attr, field_type, mutable));
|
||||
|
||||
let parsed_annotation = parse_ast_to_type_annotation_kinds(
|
||||
class_resolver,
|
||||
temp_def_list,
|
||||
unifier,
|
||||
primitives,
|
||||
annotation.as_ref(),
|
||||
vec![(class_id, class_type_vars_def.clone())].into_iter().collect(),
|
||||
)?;
|
||||
// find type vars within this return type annotation
|
||||
let type_vars_within =
|
||||
get_type_var_contained_in_type_annotation(&parsed_annotation);
|
||||
// handle the class type var and the method type var
|
||||
for type_var_within in type_vars_within {
|
||||
let TypeAnnotation::TypeVar(t) = type_var_within else {
|
||||
unreachable!("must be type var annotation")
|
||||
};
|
||||
|
||||
if !class_type_vars_def.contains(&t) {
|
||||
return Err(HashSet::from([
|
||||
format!(
|
||||
"class fields can only use type \
|
||||
vars over which the class is generic (at {})",
|
||||
annotation.location
|
||||
),
|
||||
]))
|
||||
}
|
||||
}
|
||||
type_var_to_concrete_def.insert(field_type, parsed_annotation);
|
||||
|
||||
|
||||
} else {
|
||||
return Err(HashSet::from([
|
||||
format!(
|
||||
"same class fields `{}` defined twice (at {})",
|
||||
attr, target.location
|
||||
),
|
||||
]))
|
||||
}
|
||||
} else {
|
||||
return Err(HashSet::from([
|
||||
format!(
|
||||
"unsupported statement type in class definition body (at {})",
|
||||
target.location
|
||||
),
|
||||
]))
|
||||
}
|
||||
}
|
||||
ast::StmtKind::Assign { .. } // we don't class attributes
|
||||
| ast::StmtKind::Expr { value: _, .. } // typically a docstring; ignoring all expressions matches CPython behavior
|
||||
| ast::StmtKind::Pass { .. } => {}
|
||||
|
|
|
@ -280,7 +280,6 @@ impl TopLevelComposer {
|
|||
object_id: obj_id,
|
||||
type_vars: Vec::default(),
|
||||
fields: Vec::default(),
|
||||
attr: Vec::default(),
|
||||
methods: Vec::default(),
|
||||
ancestors: Vec::default(),
|
||||
constructor,
|
||||
|
|
|
@ -99,10 +99,6 @@ pub enum TopLevelDef {
|
|||
///
|
||||
/// Name and type is mutable.
|
||||
fields: Vec<(StrRef, Type, bool)>,
|
||||
/// Class Attributes
|
||||
///
|
||||
/// Same as fields, but are immutable
|
||||
attr: Vec<(StrRef, Type, bool)>,
|
||||
/// Class methods, pointing to the corresponding function definition.
|
||||
methods: Vec<(StrRef, Type, DefinitionId)>,
|
||||
/// Ancestor classes, including itself.
|
||||
|
|
|
@ -289,7 +289,6 @@ impl TestEnvironment {
|
|||
object_id: DefinitionId(i),
|
||||
type_vars: Default::default(),
|
||||
fields: Default::default(),
|
||||
attr: Default::default(),
|
||||
methods: Default::default(),
|
||||
ancestors: Default::default(),
|
||||
resolver: None,
|
||||
|
@ -332,7 +331,6 @@ impl TestEnvironment {
|
|||
object_id: DefinitionId(defs + 1),
|
||||
type_vars: vec![v0],
|
||||
fields: [("a".into(), v0, true)].into(),
|
||||
attr: Default::default(),
|
||||
methods: Default::default(),
|
||||
ancestors: Default::default(),
|
||||
resolver: None,
|
||||
|
@ -370,7 +368,6 @@ impl TestEnvironment {
|
|||
object_id: DefinitionId(defs + 2),
|
||||
type_vars: Default::default(),
|
||||
fields: [("a".into(), int32, true), ("b".into(), fun, true)].into(),
|
||||
attr: Default::default(),
|
||||
methods: Default::default(),
|
||||
ancestors: Default::default(),
|
||||
resolver: None,
|
||||
|
@ -402,7 +399,6 @@ impl TestEnvironment {
|
|||
object_id: DefinitionId(defs + 3),
|
||||
type_vars: Default::default(),
|
||||
fields: [("a".into(), bool, true), ("b".into(), fun, false)].into(),
|
||||
attr: Default::default(),
|
||||
methods: Default::default(),
|
||||
ancestors: Default::default(),
|
||||
resolver: None,
|
||||
|
|
Loading…
Reference in New Issue