idris-lang / Idris2

A purely functional programming language with first class types
https://idris-lang.org/
Other
2.46k stars 369 forks source link

idris2.ss: support powerpc #3326

Closed barracuda156 closed 1 week ago

barracuda156 commented 1 week ago

Description

Fix building on macOS PowerPC

Should this change go in the CHANGELOG?

buzden commented 1 week ago

Every change in the bootstrap file's production procedure needs a change in the release checklist here https://github.com/idris-lang/Idris2/blob/main/Release/CHECKLIST or else it will be just overwritten on the next release

barracuda156 commented 1 week ago

@buzden Thank you. Could you please take a look and say if that will do? I am not really sure of conventions in that regard.

CodingCellist commented 1 week ago

@barracuda156 Is this something that needs to be added manually, or can we configure Chez Scheme to consider PowerPC support valid from the get-go? As far as I can tell, there is nothing functionally changing, other than adding the right magic strings to let the pattern match load the library on those architectures as well?

barracuda156 commented 1 week ago

@barracuda156 Is this something that needs to be added manually, or can we configure Chez Scheme to consider PowerPC support valid from the get-go? As far as I can tell, there is nothing functionally changing, other than adding the right magic strings to let the pattern match load the library on those architectures as well?

@CodingCellist Perhaps you can, but I have no idea where that should be done. Locally I had to patch this file to make it work. If there is some template for it elsewhere, then that is to be fixed.

dunhamsteve commented 1 week ago

This is only changing the bootstrap file, which is an output of the Idris compiler. That's fine (and necessary) for a one-time fix of bootstrap.

But it's not actually changing the source to the compiler itself. If you recompile Idris with this bootstrap compiler, it will no longer produce compatible programs.

The PR changes CompilerC-45SchemeC-45Chez-schHeader which is the output of compiling schHeader in src/Compiler/Scheme/Chez.idr (around line 98). That is the file needs to be changed for a permanent fix.

After that, I don't think we need the additional checklist item, when the next bootstrap file is generated, it should be built with the updated compiler.

barracuda156 commented 1 week ago

@dunhamsteve Thank you! For some reason BBEdit did not find that instance for me. I will fix it now and drop checklist.

barracuda156 commented 1 week ago

@dunhamsteve Is it correct now?

dunhamsteve commented 1 week ago

I think you were doing ChezSep.idr too (I missed that until I looked closer at the .ss patch). I don't know if that's used anymore, but might as well.

barracuda156 commented 1 week ago

I think you were doing ChezSep.idr too (I missed that until I looked closer at the .ss patch). I don't know if that's used anymore, but might as well.

@dunhamsteve Thank you, added that.

dunhamsteve commented 1 week ago

Looks good to me.

CodingCellist commented 1 week ago

Seems like Racket does indeed support Mac PowerPC: https://github.com/racket/racket/blob/cb410f3e9c349588f8c55aa687aa16585f16e8c1/racket/src/bc/sconfig.h#L647-L660

barracuda156 commented 1 week ago

Seems like Racket does indeed support Mac PowerPC: https://github.com/racket/racket/blob/cb410f3e9c349588f8c55aa687aa16585f16e8c1/racket/src/bc/sconfig.h#L647-L660

On a side note, this is slightly incorrect, it seems: it will hardcode the arch to ppc, even if the build is for ppc64 (__POWERPC__ evaluates as true for both).

barracuda156 commented 1 week ago

@mattpolzin This makes sense, but I need to verify if it actually works. Turns out, there is no port for racket, so I do not have it installed. Let me try writing a port and building it.

barracuda156 commented 1 week ago

@mattpolzin @dunhamsteve Looks like Racket does not specify arch anywhere besides the bootstrap file? How is it generated?

For chez, I have added ppc to support.ss now.

barracuda156 commented 1 week ago

Re Racket itself on ppc: it does not look too bad, I almost got it built, but destroot failed with a strip error: https://github.com/racket/racket/issues/5021 Perhaps should be disabled or done with different options.

CodingCellist commented 1 week ago

Looks like Racket does not specify arch anywhere besides the bootstrap file? How is it generated?

For chez, I have added ppc to support.ss now.

(and @mattpolzin)

I am also scratching my head here... As far as I can tell, based on the bootstrap files going all the way back to v0.2.0, it seems it just uses the Chez Scheme arch library code-string. Not entirely sure from where, as Compiler.Chez doesn't export its schHeader? Also, how on Earth has the Racket CI ever been passing then?... Currently doing a complete bootstrap of Idris2 backed by Racket only, to see if I can repro the Chez code being present.

But indeed, this is a problem for a different PR. I am also happy with this as-is : )

CodingCellist commented 1 week ago

I think I've narrowed it down: we include the Chez Scheme header in the Racket bootstrap file because it's derived from building idris2.ipkg and then extracting the resulting build/exec/idris2_app/idris2.rkt, which includes the Chez Scheme compiler because, well, it's part of Idris2 (afaiu this means the self-hosting version technically supports any backend code, just not the ability to run it).

I'm basing this off that afaict, CompilerC-45SchemeC-45Chez-schHeader is only invoked in the compiled Racket file as part of the CompilerC-45SchemeC-45Chez-compileToSS and CompilerC-45SchemeC-45Chez-compileToSSInc functions.

So maybe Racket handles architecture-specific things at the time of building Racket itself and then it is forever part of that install?

CodingCellist commented 1 week ago

@mattpolzin @barracuda156 do you think it would make sense to revert the changes to the bootstrap files? These will be overwritten with fresh builds on the next release (whenever that may be), and with the other changes from this PR landing, should automatically include support for ppc (at least for the Chez compiler).

mattpolzin commented 1 week ago

I think it’s worth making the changes to the bootstrap files here or else we would need to wait for a release to actually support bootstrapping on a PowerPC as is the original goal here.

barracuda156 commented 1 week ago

Anything different from these? https://github.com/idris-lang/Idris2/pull/3326/commits/76b02f5459043af34ea59e9101acf31051cf41a2 https://github.com/idris-lang/Idris2/pull/3326/commits/e4f6dc12ccaac35326d55ebbc7e5a0b3380f5f1e It works locally on ppc for me.

UPD. Ah, you were replying to a comment above, didn’t notice.