always_inline and struct problem

I'm trying to create a transpiler and I've created an architecutre in which every parsed token of the AST is repersented as ShaderOperation
struct ShaderOperation(PPrintable, CollectionElement):
var tokens: List[Token]
var name: String
var arguments: List[ShaderOperation]
var type: String

fn __init__(inout self, tokens: List[Token], name: String, arguments: List[ShaderOperation], type: String):
self.tokens = tokens
self.name = name
self.arguments = arguments
self.type = type


fn getName(inout self) -> String:
return self.name

fn setName(inout self, name:String) :
self.name = name


fn repr(inout self) -> String:
return 'ShaderOperation$(name=' + self.name + ', type=' + self.type + ')'


fn __copyinit__(inout self, existing: Self):
self.arguments = existing.arguments
self.type = existing.type
self.name = existing.name
self.tokens = existing.tokens


fn __moveinit__(inout self, owned existing: Self):
self.arguments = existing.arguments
self.type = existing.type
self.name = existing.name
self.tokens = existing.tokens
struct ShaderOperation(PPrintable, CollectionElement):
var tokens: List[Token]
var name: String
var arguments: List[ShaderOperation]
var type: String

fn __init__(inout self, tokens: List[Token], name: String, arguments: List[ShaderOperation], type: String):
self.tokens = tokens
self.name = name
self.arguments = arguments
self.type = type


fn getName(inout self) -> String:
return self.name

fn setName(inout self, name:String) :
self.name = name


fn repr(inout self) -> String:
return 'ShaderOperation$(name=' + self.name + ', type=' + self.type + ')'


fn __copyinit__(inout self, existing: Self):
self.arguments = existing.arguments
self.type = existing.type
self.name = existing.name
self.tokens = existing.tokens


fn __moveinit__(inout self, owned existing: Self):
self.arguments = existing.arguments
self.type = existing.type
self.name = existing.name
self.tokens = existing.tokens
But I get the error:
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/collections/list.mojo:186:8: error: function has recursive call to 'always_inline' function
/Users/hammad/Documents/htdocs/Hammad-Subhtdocs/Mojo/USL/shaderlab/libutils/Typing.mojo:93:8: note: to function marked 'always_inline' here
struct ShaderOperation(PPrintable, CollectionElement):
/Users/ec2-user/actions-runner/_work/modular/modular/Kernels/mojo/stdlib/collections/list.mojo:186:8: error: function has recursive call to 'always_inline' function
/Users/hammad/Documents/htdocs/Hammad-Subhtdocs/Mojo/USL/shaderlab/libutils/Typing.mojo:93:8: note: to function marked 'always_inline' here
struct ShaderOperation(PPrintable, CollectionElement):
I need the arguments property to be a list of ShaderOperations because AST nodes are usually nested inside each other
5 Replies
Darkmatter
Darkmatter3mo ago
Here you are borrowing the list of tokens and shader operations, did you mean to move them?
benny
benny3mo ago
if it’s an issue with inlining (I honestly haven’t fully read the code or error), just know that @always_inline and @no_inline both work as the names imply if i’m understanding correctly the function on line 93 as no inline may fix it
Hammad Ali
Hammad AliOP3mo ago
There is a struct on line 93, no function. Can structs be @always_inline?
benny
benny3mo ago
I’m not sure? it may be the initializer then
Hammad Ali
Hammad AliOP3mo ago
Yeah, nevermind, even though it took a significant amount of time, I re-wrote the transpiler's architecture and now it works
Want results from more Discord servers?
Add your server