Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 16-bit pointers as well as i/usize #33460

Merged
merged 1 commit into from Jun 4, 2016

Conversation

Projects
None yet
@shepmaster
Copy link
Member

shepmaster commented May 6, 2016

I'm opening this pull request to get some feedback from the community.

Although Rust doesn't support any platforms with a native 16-bit pointer at the moment, the AVR-Rust fork is working towards that goal. Keeping this forked logic up-to-date with the changes in master has been onerous so I'd like to merge these changes so that they get carried along when refactoring happens. I do not believe this should increase the maintenance burden.

This is based on the original work of Dylan McKay (@dylanmckay).

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented May 6, 2016

r? @nrc

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 6, 2016

This all seems pretty straightforward and easy to land, but in terms of keeping this up to date is there a way that we could add a simple regression test? There's a lot more places than I would have expected that need to be updated for 16-bit pointers, and ensuring that any new location stays up to date may be difficult.

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 6, 2016

is there a way that we could add a simple regression test

I'm 100% behind this, but I'm pretty stumped on how to do it. It seems like I need to be able to say "hey, this platform has 16-bit pointers", but there aren't any that do so (for now).

Do you think there's a way I could use a target description JSON file, specify "target-pointer-width": "16", and have it work on (say) x86? Then I could just do a bunch of math-like stuff, each corresponding to one of the changes being made?

a lot more places than I would have expected

You're telling me! 🌴 Unfortunately, most of them were found The Hard Way — by finding a compiler ICE building the compiler or my end code. It's a shame that there wasn't more "hey you forgot this enum value here", but most cases (reasonably) have a default value case.

@nagisa

This comment has been minimized.

Copy link
Contributor

nagisa commented May 6, 2016

The way I remember, on 16-bit systems you usually would have a distinction between far (segment+ptr) and near pointers, which seems to not be addressed here. What gives?

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 6, 2016

@nagisa I have heard tales of Ye Olde Days of near and far pointers, but I'm not sure that AVR has need for it, as it isn't a segmented memory architecture. There's some references to it when one needs to access > 64K of memory, but those seem to just be "regular" 32-bit values.

@dylanmckay

This comment has been minimized.

Copy link
Contributor

dylanmckay commented May 7, 2016

@shepmaster is right in saying AVR doesn't use segmented memory. Normal pointers are the usual 16 bits. There are a few AVR chips with a bit more memory that 16 bits can address - to access memory higher than this, there's a special IO register for which you must load the other address bits into first. It still works as an ordinary pointer, but spread over two registers.

When you try and address memory with a 32-bit pointer, the compiler does the special IO register loading for you.

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 7, 2016

a way I could use a target description JSON file

Mmm, that doesn't seem to work because it ultimately looks like cross compiling and there's no libcore or libstd for that made up platform. I'm open to any suggestions!

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 7, 2016

And If I try to follow the lead of the target-specification tests and eschew libstd and libcore, I end up triggering an LLVM assertion:

LLVM ERROR: Cannot select: 0x10e629000: i16 = FrameIndex<0>
In function: _ZN4main5_main17h49c054cd6e240b5cE
@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 7, 2016

I can get a tiny bit of test with this:

let _a: usize = 0x1_0000; // literal out of range for usize

Which indicates that, yes, 16-bit pointers only take up 16-bits. I'm not sure of the value of the test, but I'll continue poking at it. I'd still appreciate suggestions that anyone has for useful tests.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 8, 2016

Hm yeah I suspect that our main recourse for testing a patch like this would be adding automation which generated at least libcore for a 16-bit target.

Also, forgot to do this earlier, but cc @rust-lang/compiler and @rust-lang/tools

@@ -178,6 +179,7 @@ impl TargetDataLayout {

pub fn ptr_sized_integer(&self) -> Integer {
match self.pointer_size.bits() {
16 => I16,

This comment has been minimized.

@eddyb

eddyb May 9, 2016

Member

Neat.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 18, 2016

The tools team discussed this PR during triage yesterday and the conclusion was that from our perspective this seems fine. This would basically just be expanding our tier 3 platforms, which we regularly take PRs for, so no sweat on that front!

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 18, 2016

@alexcrichton that's great! I found one more tricky spot that needs to be updated, I can rebase and squash that to this commit and it should be good-to-merge then!

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 18, 2016

@alexcrichton was there any comment one way or the other about tests that would need to be added before the merge?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 18, 2016

At least from a tooling perspective we were ok not having a bunch of rigorous tests or anything, none of our tier 3 platforms do either :)

For merging, though, this cuts across a few other teams as well, so at least @rust-lang/compiler will probably want to sign off as well

Support 16-bit pointers as well as i/usize
This is based on the original work of Dylan McKay for the
[avr-rust project][ar].

[ar]: https://github.com/avr-rust/rust

@shepmaster shepmaster force-pushed the shepmaster:16-bit-pointers branch from 40e2489 to bc7595c May 19, 2016

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 19, 2016

I've fixed up the one extra spot I've found and rebased for good measure.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 19, 2016

I gave it a quick read. Looks like a fairly straight-forward patch; I've not thought deeply about what else might be needed to support 16 bit platforms, but this at least doesn't look like it would harm 32 or 64 bit. 👍

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 24, 2016

The libs team discussed this briefly at yesterday's triage and the conclusion was that from that perspective we're ok along the lines of "let's see how this plays out without bending over backwards too much"

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented May 25, 2016

I'm cool with us landing this. Might give us more street cred with micro controller community

@shepmaster

This comment has been minimized.

Copy link
Member Author

shepmaster commented May 29, 2016

Thanks for the positive reviews all around! What other teams remain to sign off?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 31, 2016

Judging by the area of change, I'd expect that at least the compiler team should weigh in. If they'd like to escalate, however, we can discuss at the core meeting.

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Jun 1, 2016

@nikomatsakis we did discuss at compiler meeting (twice I think, right?)

We didn't really attempt to form any solid consensus (we almost never have a formal quorum anyway), but no one present objected...

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jun 3, 2016

@pnkfelix indeed, we did discuss, and everybody was more-or-less in favor of doing this on an experimental basis.

@Aatch

This comment has been minimized.

Copy link
Contributor

Aatch commented Jun 4, 2016

I think the conclusion is that this is ok.

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jun 4, 2016

📌 Commit bc7595c has been approved by Aatch

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jun 4, 2016

⌛️ Testing commit bc7595c with merge 7738479...

bors added a commit that referenced this pull request Jun 4, 2016

Auto merge of #33460 - shepmaster:16-bit-pointers, r=Aatch
Support 16-bit pointers as well as i/usize

I'm opening this pull request to get some feedback from the community.

Although Rust doesn't support any platforms with a native 16-bit pointer at the moment, the [AVR-Rust][ar] fork is working towards that goal. Keeping this forked logic up-to-date with the changes in master has been onerous so I'd like to merge these changes so that they get carried along when refactoring happens. I do not believe this should increase the maintenance burden.

This is based on the original work of Dylan McKay (@dylanmckay).

[ar]: https://github.com/avr-rust/rust

@bors bors merged commit bc7595c into rust-lang:master Jun 4, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@shepmaster shepmaster deleted the shepmaster:16-bit-pointers branch Sep 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.