☝ Buildbot (Sourceware): gccrust - worker not available (master)

2023-04-05 Thread builder--- via Gcc-rust
A retry build has been detected on builder gccrust-rawhide-x86_64 while 
building gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/132/builds/802

Build state: worker not available
Revision: (unknown)
Worker: bbo1-2
Build Reason: (unknown)
Blamelist: Pierre-Emmanuel Patry 

Steps:

- 0: worker_preparation ( exception )
Logs:
- err.text: 
https://builder.sourceware.org/buildbot/#builders/132/builds/802/steps/0/logs/err_text
- err.html: 
https://builder.sourceware.org/buildbot/#builders/132/builds/802/steps/0/logs/err_html

A retry build has been detected on builder gccrust-rawhide-x86_64 while 
building gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/132/builds/803

Build state: worker not available
Revision: (unknown)
Worker: bbo1-2
Build Reason: (unknown)
Blamelist: Pierre-Emmanuel Patry 

Steps:

- 0: worker_preparation ( exception )
Logs:
- err.text: 
https://builder.sourceware.org/buildbot/#builders/132/builds/803/steps/0/logs/err_text
- err.html: 
https://builder.sourceware.org/buildbot/#builders/132/builds/803/steps/0/logs/err_html

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


☺ Buildbot (Sourceware): gccrust - build successful (master)

2023-04-05 Thread builder--- via Gcc-rust
A restored build has been detected on builder gccrust-fedora-x86_64 while 
building gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/16/builds/1020

Build state: build successful
Revision: 865f3b05ad3085e7fe1545fdffb9b5fca3db6412
Worker: bb1-1
Build Reason: (unknown)
Blamelist: Pierre-Emmanuel Patry 

Steps:

- 0: worker_preparation ( success )

- 1: git checkout ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/1/logs/stdio

- 2: rm -rf gccrs-build ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/2/logs/stdio

- 3: configure ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/3/logs/stdio
- config.log: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/3/logs/config_log

- 4: make ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/4/logs/stdio
- warnings (34): 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/4/logs/warnings__34_

- 5: make check ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/5/logs/stdio
- rust.sum: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/5/logs/rust_sum
- rust.log: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/5/logs/rust_log
- warnings (6): 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/5/logs/warnings__6_

- 6: grep unexpected rust.sum ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/6/logs/stdio

- 7: prep ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/7/logs/stdio

- 8: build bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/8/logs/stdio

- 9: fetch bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/9/logs/stdio

- 10: unpack bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/10/logs/stdio

- 11: pass .bunsen.source.gitname ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/11/logs/stdio

- 12: pass .bunsen.source.gitdescribe ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/12/logs/stdio

- 13: pass .bunsen.source.gitbranch ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/13/logs/stdio

- 14: pass .bunsen.source.gitrepo ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/14/logs/stdio

- 15: upload to bunsen ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/15/logs/stdio

- 16: clean up ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/16/logs/stdio

- 17: rm -rf gccrs-build_1 ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1020/steps/17/logs/stdio

A restored build has been detected on builder gccrust-debian-i386 while 
building gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/27/builds/1035

Build state: build successful
Revision: 865f3b05ad3085e7fe1545fdffb9b5fca3db6412
Worker: debian-i386-2
Build Reason: (unknown)
Blamelist: Pierre-Emmanuel Patry 

Steps:

- 0: worker_preparation ( success )

- 1: git checkout ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/1/logs/stdio

- 2: rm -rf gccrs-build ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/2/logs/stdio

- 3: configure ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/3/logs/stdio
- config.log: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/3/logs/config_log

- 4: make ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/4/logs/stdio
- warnings (29): 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/4/logs/warnings__29_

- 5: make check ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/5/logs/stdio
- rust.sum: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1035/steps/5/logs/rust_sum
- rust.log: 
https://builder.sourceware.org/

☝ Buildbot (Sourceware): gccrust - worker not available (master)

2023-04-05 Thread builder--- via Gcc-rust
A retry build has been detected on builder gccrust-opensusetw-x86_64 while 
building gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/103/builds/873

Build state: worker not available
Revision: (unknown)
Worker: bbo1-2
Build Reason: (unknown)
Blamelist: Pierre-Emmanuel Patry 

Steps:

- 0: worker_preparation ( exception )
Logs:
- err.text: 
https://builder.sourceware.org/buildbot/#builders/103/builds/873/steps/0/logs/err_text
- err.html: 
https://builder.sourceware.org/buildbot/#builders/103/builds/873/steps/0/logs/err_html

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


☠ Buildbot (Sourceware): gccrust - failed 'grep unexpected ...' (failure) (master)

2023-04-05 Thread builder--- via Gcc-rust
A new failure has been detected on builder gccrust-fedora-x86_64 while building 
gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/16/builds/1019

Build state: failed 'grep unexpected ...' (failure)
Revision: a7302b77e3915c55ac043401696c84fcdbb96336
Worker: bb1-2
Build Reason: (unknown)
Blamelist: Pierre-Emmanuel Patry 

Steps:

- 0: worker_preparation ( success )

- 1: git checkout ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/1/logs/stdio

- 2: rm -rf gccrs-build ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/2/logs/stdio

- 3: configure ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/3/logs/stdio
- config.log: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/3/logs/config_log

- 4: make ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/4/logs/stdio
- warnings (34): 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/4/logs/warnings__34_

- 5: make check ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/5/logs/stdio
- rust.sum: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/5/logs/rust_sum
- rust.log: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/5/logs/rust_log
- warnings (6): 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/5/logs/warnings__6_

- 6: grep unexpected rust.sum ( failure )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/6/logs/stdio

- 7: prep ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/7/logs/stdio

- 8: build bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/8/logs/stdio

- 9: fetch bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/9/logs/stdio

- 10: unpack bunsen.cpio.gz ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/10/logs/stdio

- 11: pass .bunsen.source.gitname ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/11/logs/stdio

- 12: pass .bunsen.source.gitdescribe ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/12/logs/stdio

- 13: pass .bunsen.source.gitbranch ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/13/logs/stdio

- 14: pass .bunsen.source.gitrepo ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/14/logs/stdio

- 15: upload to bunsen ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/15/logs/stdio

- 16: clean up ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/16/logs/stdio

- 17: rm -rf gccrs-build_1 ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1019/steps/17/logs/stdio

A new failure has been detected on builder gccrust-debian-i386 while building 
gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/27/builds/1034

Build state: failed 'grep unexpected ...' (failure)
Revision: a7302b77e3915c55ac043401696c84fcdbb96336
Worker: debian-i386
Build Reason: (unknown)
Blamelist: Pierre-Emmanuel Patry 

Steps:

- 0: worker_preparation ( success )

- 1: git checkout ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/1/logs/stdio

- 2: rm -rf gccrs-build ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/2/logs/stdio

- 3: configure ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/3/logs/stdio
- config.log: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/3/logs/config_log

- 4: make ( warnings )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/4/logs/stdio
- warnings (29): 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/4/logs/warnings__29_

- 5: make check ( success )
Logs:
- stdio: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/5/logs/stdio
- rust.sum: 
https://builder.sourceware.org/buildbot/#builders/27/builds/1034/steps/5/logs/rust_sum
- rust.l

☝ Buildbot (Sourceware): gccrust - worker not available (master)

2023-04-05 Thread builder--- via Gcc-rust
A retry build has been detected on builder gccrust-opensusetw-x86_64 while 
building gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/103/builds/875

Build state: worker not available
Revision: (unknown)
Worker: bbo1-1
Build Reason: (unknown)
Blamelist: Philip Herron 

Steps:

- 0: worker_preparation ( exception )
Logs:
- err.text: 
https://builder.sourceware.org/buildbot/#builders/103/builds/875/steps/0/logs/err_text
- err.html: 
https://builder.sourceware.org/buildbot/#builders/103/builds/875/steps/0/logs/err_html

A retry build has been detected on builder gccrust-opensusetw-x86_64 while 
building gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/103/builds/876

Build state: worker not available
Revision: (unknown)
Worker: bbo1-1
Build Reason: (unknown)
Blamelist: Philip Herron 

Steps:

- 0: worker_preparation ( exception )
Logs:
- err.text: 
https://builder.sourceware.org/buildbot/#builders/103/builds/876/steps/0/logs/err_text
- err.html: 
https://builder.sourceware.org/buildbot/#builders/103/builds/876/steps/0/logs/err_html

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


☝ Buildbot (Sourceware): gccrust - worker not available (master)

2023-04-05 Thread builder--- via Gcc-rust
A retry build has been detected on builder gccrust-fedora-x86_64 while building 
gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/16/builds/1024

Build state: worker not available
Revision: (unknown)
Worker: bbo1-2
Build Reason: (unknown)
Blamelist: Philip Herron 

Steps:

- 0: worker_preparation ( exception )
Logs:
- err.text: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1024/steps/0/logs/err_text
- err.html: 
https://builder.sourceware.org/buildbot/#builders/16/builds/1024/steps/0/logs/err_html

A failed build has been detected on builder gccrust-gentoo-sparc while building 
gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/241/builds/448

Build state: failed 'grep unexpected ...' (failure)
Revision: 4713107dffad79ac0c7863411928b536f90f768a
Worker: gentoo-sparc
Build Reason: (unknown)
Blamelist: A. Wilcox , Abdul Rafey 
, Alan Modra , Aldy Hernandez 
, Alex Coplan , Alexander Monakov 
, Alexandre Oliva , Alexandre Oliva 
, Allan McRae , Andre Simoes Dias Vieira 
, Andre Vehreschild , Andre 
Vieira , Andrea Corallo 
, Andreas Krebbel , Andreas 
Schwab , Andreas Schwab , Andrew 
Carlotti , Andrew Carlotti , 
Andrew MacLeod , Andrew Pinski , 
Andrew Pinski , Andrew Stubbs , 
Antoni Boucher , Ard Biesheuvel , Arjun 
Shankar , Arnaud Charlet , Arsen 
Arsenovic , Arsen Arsenović , ArshErgon 
, Artem Klimov , Arthur Cohen 
, Avinash Sonawane , Benno Evers 
, Bernd Kuhls , Bernhard 
Reutner-Fischer , Bernhard Reutner-Fischer 
, Bill Schmidt , Bill Seurer 
, Björn Schäpers , Bob Duff 
, Boris Yakobowski , Bruce Korb 
, Bruno Haible , Cedric Landet 
, Cesar Philippidis , 
Charles-François Natali , Chenghua Xu 
, Chenghua Xu , Christoph 
Müllner , Christophe Lyon 
, Christophe Lyon , 
Chung-Ju Wu , Chung-Lin Tang , 
Claire Dross , Claudiu Zissulescu , 
Claudiu Zissulescu , Clément Chigot , 
Clément Chigot , CohenArthur , 
Cui,Lili , Cupertino Miranda 
, Dan Li , Daniel 
Mercier , Dave , David Edelsohn 
, David Faust , David Malcolm 
, David Seifert , Detlef Vollmann 
, Dimitar Dimitrov , Dimitrij Mijoski 
, Dimitrije Milosevic , 
Dimitrije Milošević , Dmitriy Anisimkov 
, Dongsheng Song , Doug Rupp 
, Ed Catmur , Ed Schonberg 
, Ed Smith-Rowland , Emanuele 
Micheletti , Eric Biggers 
, Eric Botcazou , Eric Botcazou 
, Eric Gallager , Etienne Servais 
, Eugene Rozenfeld , Faisal Abbas 
<90.abbasfai...@gmail.com>, Faisal Abbas , Fedor 
Rybin , Fei Gao , Flavio Cruz 
, Florian Weimer , Francois-Xavier 
Coudert , Francois-Xavier Coudert , 
François Dumont , Frederik Harwath 
, Fritz Reese , Frolov Daniil 
, GCC Administrator , Gaius 
Mulley , Gary Dismukes , 
Georg-Johann Lay , Gerald Pfeifer , Ghjuvan 
Lacambre , Giuliano Belinassi , 
Guillermo E. Martinez , H.J. Lu 
, Hafiz Abid Qadeer , Hans-Peter 
Nilsson , Haochen Gui , Haochen Jiang 
, Harald Anlauf , Hongyu Wang 
, Hu, Lin1 , Iain Buclaw 
, Iain Sandoe , Ian Lance Taylor 
, Ilya Leoshkevich , Immad Mir 
, Immad Mir , Indu Bhagat 
, Iskander Shakirzyanov , Jakob 
Hasse <0xja...@users.noreply.github.com>, Jakub Dupak , 
Jakub Jelinek , Jan Beulich , Jan Hubicka 
, Jan-Benedict Glaw , Jason Merrill 
, Javier Miranda , Jeff Chapman II 
, Jeff Law , Jeff Law 
, Jerry DeLisle , Jia-Wei Chen 
, Jia-wei Chen , Jiakun Fan 
<120090...@link.cuhk.edu.cn>, Jiawei , Jin Ma 
, Jinyang He , Jiufu Guo 
, Joao Azevedo , Joel Brobecker 
, Joel Holdsworth , Joel 
Phillips , Joel Teichroeb , 
Joffrey Huguet , Johannes Kanig , 
Johannes Kliemann , John David Anglin 
, Jonathan Wakely , Jonathan Yong 
<10wa...@gmail.com>, Jose E. Marchesi , Joseph Myers 
, Josue Nava Bello , José Rui 
Faustino de Sousa , Ju-Zhe Zhong , 
Julia Lapenko , Julian Brown 
, Julien Bortolussi , Justin 
Squirek , Jørgen Kvalsvik 
, Keef Aragon , 
Kewen Lin , Kewen.Lin , Kim Kuparinen 
, Kito Cheng , Kong 
Lingling , Kwok Cheung Yeung , 
Kyrylo Tkachov , Kévin Le Gouguec 
, LIU Hao , Lewis Hyatt 
, Liaiss Merzougue , LiaoShihua 
, Lili Cui , Liwei Xu 
, Lorenzo Salvadore , Lulu 
Cheng , Lyra , M V V S Manoj Kumar 
, MAHAD , Maciej W. Rozycki 
, Maciej W. Rozycki , Mahmoud Mohamed 
, Marc Nieper-Wißkirchen , 
Marc Poulhiès , Marc Poulhiès , Marcel 
Vollweiler , Marco Falke , 
Marek Polacek , Mark Mentovai , Mark 
Wielaard , Martin Jambor , Martin Liska 
, Martin Liška , Martin Sebor 
, Martin Uecker , Matthias Kretz 
, Max Filippov , Mayshao 
, Meghan Denny , Michael Collison 
, Michael Eager , Michael Meissner 
, Mikael Morin , Mikhail Ablakatov 
, Monk Chiang , Murray Steele 
, Nathan Sidwell , Nathaniel Shead 
, Navid Rahimi , Nick 
Clifton , Nikos Alexandris , 
Nirmal Patel , Olivier Hainque , Owen 
Avery , Palmer Dabbelt , 
Parthib <94271200+parthib...@users.noreply.github.com>, Parthib 
, Pascal Obry , Pat Haugen 
, Patrick Bernardi , Patrick 
Palka , Paul A. Clarke , Paul Thomas 
, Paul-Antoine Arras , Pekka Seppänen 
, Peter Bergner , Petter Tomner 
, Philip Herron , Philip Herr

☠ Buildbot (Sourceware): gccrust - failed 'grep unexpected ...' (failure) (master)

2023-04-05 Thread builder--- via Gcc-rust
A failed build has been detected on builder gccrust-gentoo-sparc while building 
gccrust.

Full details are available at:
https://builder.sourceware.org/buildbot/#builders/241/builds/450

Build state: failed 'grep unexpected ...' (failure)
Revision: 4d663acdb6e685c07818aa4229c7b1f2224d678b
Worker: gentoo-sparc-big
Build Reason: (unknown)
Blamelist: A. Wilcox , Abdul Rafey 
, Alan Modra , Aldy Hernandez 
, Alex Coplan , Alexander Monakov 
, Alexandre Oliva , Alexandre Oliva 
, Allan McRae , Andre Simoes Dias Vieira 
, Andre Vehreschild , Andre 
Vieira , Andrea Corallo 
, Andreas Krebbel , Andreas 
Schwab , Andreas Schwab , Andrew 
Carlotti , Andrew Carlotti , 
Andrew MacLeod , Andrew Pinski , 
Andrew Pinski , Andrew Stubbs , 
Antoni Boucher , Ard Biesheuvel , Arjun 
Shankar , Arnaud Charlet , Arsen 
Arsenovic , Arsen Arsenović , ArshErgon 
, Artem Klimov , Arthur Cohen 
, Avinash Sonawane , Benno Evers 
, Bernd Kuhls , Bernhard 
Reutner-Fischer , Bernhard Reutner-Fischer 
, Bill Schmidt , Bill Seurer 
, Björn Schäpers , Bob Duff 
, Boris Yakobowski , Bruce Korb 
, Bruno Haible , Cedric Landet 
, Cesar Philippidis , 
Charles-François Natali , Chenghua Xu 
, Chenghua Xu , Christoph 
Müllner , Christophe Lyon 
, Christophe Lyon , 
Chung-Ju Wu , Chung-Lin Tang , 
Claire Dross , Claudiu Zissulescu , 
Claudiu Zissulescu , Clément Chigot , 
Clément Chigot , CohenArthur , 
Cui,Lili , Cupertino Miranda 
, Dan Li , Daniel 
Mercier , Dave , David Edelsohn 
, David Faust , David Malcolm 
, David Seifert , Detlef Vollmann 
, Dimitar Dimitrov , Dimitrij Mijoski 
, Dimitrije Milosevic , 
Dimitrije Milošević , Dmitriy Anisimkov 
, Dongsheng Song , Doug Rupp 
, Ed Catmur , Ed Schonberg 
, Ed Smith-Rowland , Emanuele 
Micheletti , Eric Biggers 
, Eric Botcazou , Eric Botcazou 
, Eric Gallager , Etienne Servais 
, Eugene Rozenfeld , Faisal Abbas 
<90.abbasfai...@gmail.com>, Faisal Abbas , Fedor 
Rybin , Fei Gao , Flavio Cruz 
, Florian Weimer , Francois-Xavier 
Coudert , Francois-Xavier Coudert , 
François Dumont , Frederik Harwath 
, Fritz Reese , Frolov Daniil 
, GCC Administrator , Gaius 
Mulley , Gary Dismukes , 
Georg-Johann Lay , Gerald Pfeifer , Ghjuvan 
Lacambre , Giuliano Belinassi , 
Guillermo E. Martinez , H.J. Lu 
, Hafiz Abid Qadeer , Hans-Peter 
Nilsson , Haochen Gui , Haochen Jiang 
, Harald Anlauf , Hongyu Wang 
, Hu, Lin1 , Iain Buclaw 
, Iain Sandoe , Ian Lance Taylor 
, Ilya Leoshkevich , Immad Mir 
, Immad Mir , Indu Bhagat 
, Iskander Shakirzyanov , Jakob 
Hasse <0xja...@users.noreply.github.com>, Jakub Dupak , 
Jakub Jelinek , Jan Beulich , Jan Hubicka 
, Jan-Benedict Glaw , Jason Merrill 
, Javier Miranda , Jeff Chapman II 
, Jeff Law , Jeff Law 
, Jerry DeLisle , Jia-Wei Chen 
, Jia-wei Chen , Jiakun Fan 
<120090...@link.cuhk.edu.cn>, Jiawei , Jin Ma 
, Jinyang He , Jiufu Guo 
, Joao Azevedo , Joel Brobecker 
, Joel Holdsworth , Joel 
Phillips , Joel Teichroeb , 
Joffrey Huguet , Johannes Kanig , 
Johannes Kliemann , John David Anglin 
, Jonathan Wakely , Jonathan Yong 
<10wa...@gmail.com>, Jose E. Marchesi , Joseph Myers 
, Josue Nava Bello , José Rui 
Faustino de Sousa , Ju-Zhe Zhong , 
Julia Lapenko , Julian Brown 
, Julien Bortolussi , Justin 
Squirek , Jørgen Kvalsvik 
, Keef Aragon , 
Kewen Lin , Kewen.Lin , Kim Kuparinen 
, Kito Cheng , Kong 
Lingling , Kwok Cheung Yeung , 
Kyrylo Tkachov , Kévin Le Gouguec 
, LIU Hao , Lewis Hyatt 
, Liaiss Merzougue , LiaoShihua 
, Lili Cui , Liwei Xu 
, Lorenzo Salvadore , Lulu 
Cheng , Lyra , M V V S Manoj Kumar 
, MAHAD , Maciej W. Rozycki 
, Maciej W. Rozycki , Mahmoud Mohamed 
, Marc Nieper-Wißkirchen , 
Marc Poulhiès , Marc Poulhiès , Marcel 
Vollweiler , Marco Falke , 
Marek Polacek , Mark Mentovai , Mark 
Wielaard , Martin Jambor , Martin Liska 
, Martin Liška , Martin Sebor 
, Martin Uecker , Matthias Kretz 
, Max Filippov , Mayshao 
, Meghan Denny , Michael Collison 
, Michael Eager , Michael Meissner 
, Mikael Morin , Mikhail Ablakatov 
, Monk Chiang , Murray Steele 
, Nathan Sidwell , Nathaniel Shead 
, Navid Rahimi , Nick 
Clifton , Nikos Alexandris , 
Nirmal Patel , Olivier Hainque , Owen 
Avery , Palmer Dabbelt , 
Parthib <94271200+parthib...@users.noreply.github.com>, Parthib 
, Pascal Obry , Pat Haugen 
, Patrick Bernardi , Patrick 
Palka , Paul A. Clarke , Paul Thomas 
, Paul-Antoine Arras , Pekka Seppänen 
, Peter Bergner , Petter Tomner 
, Philip Herron , Philip Herron 
, Philipp Fent , Philipp Tomsich 
, Pierre-Emmanuel Patry 
, Pierre-Marie de Rodat 
, Piotr Trojanek , Prajwal S N 
, Prathamesh Kulkarni 
, Przemyslaw Wirkus 
, Qian Jianhua , Qian Jianhua 
, Qing Zhao , Quentin Ochem 
, Raiki Tamura , Rainer Orth 
, Rainer Orth , Ramana 
Radhakrishnan , Ramana Radhakrishnan 
, Raoni Fassina Firmino , 
Raphael Moreira Zinsly , Rasmus Villemoes 
, Rasmus Villemoes , 
Richard Ball , Richard Biener , 
Richard Earnshaw , Richard Henderson , 
Richard Purdie , Richard Sandiford 
, Rimvydas Jasinskas , Robin 
Dapp , Roger Sayle , Romain 
Begue

[committed 02/88] gccrs: unsafe: check use of `target_feature` attribute

2023-04-05 Thread arthur . cohen
From: Prajwal S N 

The `target_feature` attribute is for conditional compilation and may or
may not compile on all platforms. Using it requires an unsafe function
or block.

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc (check_target_attr): New 
function.
(UnsafeChecker::check_function_attr): Call into `check_target_attr`.
(UnsafeChecker::visit): Check for target_feature attributes.
* checks/errors/rust-unsafe-checker.h: Add declarations.
* util/rust-attributes.cc: Add attribute.

gcc/testsuite/ChangeLog:

* rust/compile/unsafe11.rs: New test.

Signed-off-by: Prajwal S N 
---
 gcc/rust/checks/errors/rust-unsafe-checker.cc | 29 ++-
 gcc/rust/checks/errors/rust-unsafe-checker.h  |  5 
 gcc/rust/util/rust-attributes.cc  |  3 ++
 gcc/testsuite/rust/compile/unsafe11.rs|  8 +
 4 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/unsafe11.rs

diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc 
b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 94808632c04..3c369a2a81a 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -179,6 +179,31 @@ UnsafeChecker::check_function_call (HirId node_id, 
Location locus)
   locus);
 }
 
+static void
+check_target_attr (HIR::Function *fn, Location locus)
+{
+  if (std::any_of (fn->get_outer_attrs ().begin (),
+  fn->get_outer_attrs ().end (),
+  [] (const AST::Attribute &attr) {
+return attr.get_path ().as_string () == "target_feature";
+  }))
+rust_error_at (locus,
+  "call to function with %<#[target_feature]%> requires "
+  "unsafe function or block");
+}
+
+void
+UnsafeChecker::check_function_attr (HirId node_id, Location locus)
+{
+  if (unsafe_context.is_in_context ())
+return;
+
+  auto maybe_fn = mappings.lookup_hir_item (node_id);
+
+  if (maybe_fn && maybe_fn->get_item_kind () == Item::ItemKind::Function)
+check_target_attr (static_cast (maybe_fn), locus);
+}
+
 void
 UnsafeChecker::visit (Lifetime &)
 {}
@@ -398,11 +423,13 @@ UnsafeChecker::visit (CallExpr &expr)
 
   rust_assert (mappings.lookup_node_to_hir (ref_node_id, &definition_id));
 
-  // At this point we have the function's HIR Id. There are two checks we
+  // At this point we have the function's HIR Id. There are three checks we
   // must perform:
   // 1. The function is an unsafe one
   // 2. The function is an extern one
+  // 3. The function is marked with a target_feature attribute
   check_function_call (definition_id, expr.get_locus ());
+  check_function_attr (definition_id, expr.get_locus ());
 
   if (expr.has_params ())
 for (auto &arg : expr.get_arguments ())
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h 
b/gcc/rust/checks/errors/rust-unsafe-checker.h
index 9df44db06a9..2abd3a62351 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.h
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.h
@@ -46,6 +46,11 @@ private:
*/
   void check_function_call (HirId node_id, Location locus);
 
+  /**
+   * Check if any unsafe attributes are present on a function
+   */
+  void check_function_attr (HirId node_id, Location locus);
+
   StackedContexts unsafe_context;
 
   Resolver::TypeCheckContext &context;
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 33f2c932d09..0458f6902b7 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -41,6 +41,9 @@ static const BuiltinAttrDefinition __definitions[]
  {"repr", CODE_GENERATION},
  {"path", EXPANSION},
  {"macro_use", NAME_RESOLUTION},
+ // FIXME: This is not implemented yet, see
+ // https://github.com/Rust-GCC/gccrs/issues/1475
+ {"target_feature", CODE_GENERATION},
  // From now on, these are reserved by the compiler and gated through
  // #![feature(rustc_attrs)]
  {"rustc_inherit_overflow_checks", CODE_GENERATION}};
diff --git a/gcc/testsuite/rust/compile/unsafe11.rs 
b/gcc/testsuite/rust/compile/unsafe11.rs
new file mode 100644
index 000..c87902fcd5f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/unsafe11.rs
@@ -0,0 +1,8 @@
+#[target_feature(sse)]
+fn foo() {
+let a: usize = 0;
+}
+
+fn main() {
+foo() // { dg-error "requires unsafe function or block" }
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


Rust front-end update 2023-04-05

2023-04-05 Thread arthur . cohen
Hi everyone,

This patchset contains around 80 commits concerning the Rust frontend.

We have been hard at work trying to get the Rust core library to
compile, and hope to push more commits in the coming days as we try
and upstream a more recent version of gccrs. All of the team has done
a tremendous amount of work in the last few weeks, as we get closer
and closer to compiling libcore 1.49.

Our focus before GCC 13 releases is to improve the documentation of the
compiler and write more about the various flags used by the frontend,
which a user will need to understand and interact with.

The commits we will be pushing before GCC 13 releases will not contain
any "major breakthrough", as some functionality required to compile
libcore properly will still take some time to implement. Very often used
Rust macros such as `format_args` are defined within the core library,
and require a high amount of work on the compiler side.

Furthermore, integrating libcore as part of GCC will require
significant build system changes which are incompatible with the current
GCC stage. We will be making these changes as soon as possible and
integrate a version of libcore in GCC 14, as well as an implementation
of the libproc_macro crate. We will be submitting these patches and
pinging build system experts for extensive reviewing.

Thank you to everyone involved with the project, and to everyone who
has helped us.

All the best,

Arthur


-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 03/88] gccrs: Check for mutable references in const functions

2023-04-05 Thread arthur . cohen
From: Dave 

Use StackedContext instead. Fix error string

Signed-off-by: Dave Evans 

(Squashed commits) Check for mutable references in const functions using 
StackedContext

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc (ConstChecker::visit): Use 
StackedContext
class.

gcc/testsuite/ChangeLog:

* rust/compile/const10.rs: New test.

Signed-off-by: Dave Evans 
---
 gcc/rust/checks/errors/rust-const-checker.cc | 8 ++--
 gcc/testsuite/rust/compile/const10.rs| 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/const10.rs

diff --git a/gcc/rust/checks/errors/rust-const-checker.cc 
b/gcc/rust/checks/errors/rust-const-checker.cc
index 576c1b170d6..7e31c9f9c28 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -898,8 +898,12 @@ ConstChecker::visit (RawPointerType &)
 {}
 
 void
-ConstChecker::visit (ReferenceType &)
-{}
+ConstChecker::visit (ReferenceType &type)
+{
+  if (const_context.is_in_context () && type.is_mut ())
+rust_error_at (type.get_locus (),
+  "mutable references are not allowed in constant functions");
+}
 
 void
 ConstChecker::visit (ArrayType &type)
diff --git a/gcc/testsuite/rust/compile/const10.rs 
b/gcc/testsuite/rust/compile/const10.rs
new file mode 100644
index 000..9ab82744fbd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/const10.rs
@@ -0,0 +1,3 @@
+const fn foo (a: &mut i32) { // { dg-error "mutable references are not allowed 
in constant functions" }
+   *a = 1;
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 06/88] gccrs: Add name resolution to generic argument associated item bindings

2023-04-05 Thread arthur . cohen
From: Philip Herron 

When specifying generic arguments to Traits we can also specify the
associated types using `` syntax we need to add
name resolution to the type argument here and rely on the type
resolution pass to ensure the associated type exists and to setup the
associated types accordingly.

Addresses #1720

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveGenericArgs::go): Add name 
resolution to
Trait items.

Signed-off-by: Philip Herron 
---
 gcc/rust/resolve/rust-ast-resolve-type.cc | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc 
b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 16d05f3792b..28ab0697431 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -589,6 +589,11 @@ ResolveGenericArgs::go (AST::GenericArgs &generic_args,
 
   resolver.resolve_disambiguated_generic (arg);
 }
+
+  for (auto &binding : generic_args.get_binding_args ())
+{
+  ResolveType::go (binding.get_type ().get ());
+}
 }
 
 } // namespace Resolver
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 01/88] gccrs: fatal_error_flag: Fix typo in error message

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Fix typo.
---
 gcc/rust/rust-session-manager.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 732aabe1f26..70b058ff992 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -438,7 +438,7 @@ Session::compile_crate (const char *filename)
   "manner by passing the following flag:\n\n"
   "`-frust-incomplete-and-experimental-compiler-do-not-use`\n\nor by "
   "defining the following environment variable (any value will "
-  "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor"
+  "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor "
   "cargo-gccrs, this means passing\n\n"
   "GCCRS_EXTRA_FLAGS=\"-frust-incomplete-and-experimental-compiler-do-not-"
   "use\"\n\nas an environment variable.");
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 07/88] gccrs: Support associated type bound arguments

2023-04-05 Thread arthur . cohen
From: Philip Herron 

This patch adds support for the GenercArgsBinding type, where you can
specify the associated types of a trait bound using `` style
syntax. Note that the type-resolution relys on the i32 impl for Add
as type resolution will resolve the `a+a` to the core::ops::Add method
so code generation will require this to exist.

I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly
creating an HIR::GenericArgs with a trait-object type and causing issues.
the parsing is still correct but we dont have the mechanism to represent
this in AST and HIR properly. I think we will need a new HIR::GenericArgs
AssociatedTypeBindingBound or something similar. We are still lacking
bounds checking during are type coercions and unifications so running this
example using an f32 will wrongly pass type checking, this will need
addressed next.

Fixes #1720

gcc/rust/ChangeLog:

* hir/tree/rust-hir-path.h: Add const get_identifier and get_type 
method.
* typecheck/rust-hir-path-probe.h: Use new SubstitutionArgumentMappings 
constructor.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 
Likewise.
* typecheck/rust-tyty-bounds.cc 
(TypeCheckBase::get_predicate_from_bound):
Do not assert failure on size mismatch anymore.
(TypeBoundPredicate::TypeBoundPredicate): Use new 
SubstitutionArgumentMappings constructor.
(TypeBoundPredicate::operator=): Likewise.
(TypeBoundPredicate::apply_generic_arguments): Likewise.
(TypeBoundPredicateItem::get_tyty_for_receiver): Likewise.
(TypeBoundPredicate::get_num_associated_bindings): Likewise.
(TypeBoundPredicate::lookup_associated_type): Fix implementation for 
new system.
(TypeBoundPredicate::get_associated_type_items): Likewise.
* typecheck/rust-tyty.cc 
(SubstitutionRef::get_mappings_from_generic_args): Add new
behavior.
(SubstitutionRef::infer_substitions): Use new constructor and add 
comment.
(SubstitutionRef::solve_missing_mappings_from_this): Use new 
constructor.
* typecheck/rust-tyty.h: Define new constructors.

gcc/testsuite/ChangeLog:

* rust/compile/bounds.rs: change to use -fsyntax-only
* rust/execute/torture/issue-1720.rs: New test.

Signed-off-by: Philip Herron 
---
 gcc/rust/hir/tree/rust-hir-path.h |  4 +-
 gcc/rust/typecheck/rust-hir-path-probe.h  |  3 +-
 gcc/rust/typecheck/rust-hir-trait-resolve.cc  | 11 +--
 .../typecheck/rust-hir-type-check-expr.cc | 12 ++-
 gcc/rust/typecheck/rust-tyty-bounds.cc| 89 ---
 gcc/rust/typecheck/rust-tyty.cc   | 73 +--
 gcc/rust/typecheck/rust-tyty.h| 48 --
 gcc/testsuite/rust/compile/bounds.rs  |  8 +-
 .../rust/execute/torture/issue-1720.rs| 26 ++
 9 files changed, 236 insertions(+), 38 deletions(-)
 create mode 100644 gcc/testsuite/rust/execute/torture/issue-1720.rs

diff --git a/gcc/rust/hir/tree/rust-hir-path.h 
b/gcc/rust/hir/tree/rust-hir-path.h
index 17eedb8d741..740de9391a0 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -105,9 +105,11 @@ public:
 
   std::string as_string () const;
 
-  Identifier get_identifier () const { return identifier; }
+  Identifier &get_identifier () { return identifier; }
+  const Identifier &get_identifier () const { return identifier; }
 
   std::unique_ptr &get_type () { return type; }
+  const std::unique_ptr &get_type () const { return type; }
 
   Location get_locus () const { return locus; }
 };
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h 
b/gcc/rust/typecheck/rust-hir-path-probe.h
index 6d6bcf8e7cd..bb8698ce0e1 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -362,7 +362,8 @@ protected:
mappings.push_back (TyTy::SubstitutionArg (param, receiver->clone ()));
 
Location locus; // FIXME
-   TyTy::SubstitutionArgumentMappings args (std::move (mappings), locus);
+   TyTy::SubstitutionArgumentMappings args (std::move (mappings), {},
+locus);
trait_item_tyty = SubstMapperInternal::Resolve (trait_item_tyty, args);
   }
 
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 2ec9b2ef83e..85cad8e9c21 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -441,8 +441,8 @@ AssociatedImplTrait::setup_associated_types (
param_mappings[p.get_symbol ()] = a.get_tyty ()->get_ref ();
   };
 
-  TyTy::SubstitutionArgumentMappings infer_arguments (std::move (args), locus,
- param_subst_cb);
+  TyTy::SubstitutionArgumentMappings infer_arguments (std::move (args), {},
+   

[committed 15/88] gccrs: Add HIR lowering for GroupedPattern

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Add proper 
visitor.
* hir/rust-ast-lower-pattern.h: Declare it.

Signed-off-by: Owen Avery 
---
 gcc/rust/hir/rust-ast-lower-pattern.cc | 16 
 gcc/rust/hir/rust-ast-lower-pattern.h  |  1 +
 2 files changed, 17 insertions(+)

diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc 
b/gcc/rust/hir/rust-ast-lower-pattern.cc
index 30a188286c8..8ee3a979a33 100644
--- a/gcc/rust/hir/rust-ast-lower-pattern.cc
+++ b/gcc/rust/hir/rust-ast-lower-pattern.cc
@@ -243,5 +243,21 @@ ASTLoweringPattern::visit (AST::RangePattern &pattern)
 std::move (upper_bound), pattern.get_locus ());
 }
 
+void
+ASTLoweringPattern::visit (AST::GroupedPattern &pattern)
+{
+  auto crate_num = mappings->get_current_crate ();
+  Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (),
+mappings->get_next_hir_id (crate_num),
+UNKNOWN_LOCAL_DEFID);
+
+  HIR::Pattern *inner
+= ASTLoweringPattern::translate (pattern.get_pattern_in_parens ().get ());
+
+  translated
+= new HIR::GroupedPattern (mapping, std::unique_ptr (inner),
+  pattern.get_locus ());
+}
+
 } // namespace HIR
 } // namespace Rust
diff --git a/gcc/rust/hir/rust-ast-lower-pattern.h 
b/gcc/rust/hir/rust-ast-lower-pattern.h
index 8b191d56868..0075e27e9c0 100644
--- a/gcc/rust/hir/rust-ast-lower-pattern.h
+++ b/gcc/rust/hir/rust-ast-lower-pattern.h
@@ -39,6 +39,7 @@ public:
   void visit (AST::TuplePattern &pattern) override;
   void visit (AST::LiteralPattern &pattern) override;
   void visit (AST::RangePattern &pattern) override;
+  void visit (AST::GroupedPattern &pattern) override;
 
 private:
   ASTLoweringPattern ();
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 16/88] gccrs: Add get_item method for HIR::GroupedPattern

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h: Add get_item method.

Signed-off-by: Owen Avery 
---
 gcc/rust/hir/tree/rust-hir-pattern.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h 
b/gcc/rust/hir/tree/rust-hir-pattern.h
index 80fa9b791a7..b7a230c526f 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -1269,6 +1269,12 @@ public:
 return PatternType::GROUPED;
   }
 
+  std::unique_ptr &get_item () { return pattern_in_parens; }
+  const std::unique_ptr &get_item () const
+  {
+return pattern_in_parens;
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object rather
* than base */
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 20/88] gccrs: moved operator.h to util/rust-operators.h

2023-04-05 Thread arthur . cohen
From: Abdul Rafey 

gcc/rust/ChangeLog:

* ast/rust-ast.cc: Fix include list.
* ast/rust-expr.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* rust-backend.h: Likewise.
* util/rust-lang-item.h: Likewise.
* operator.h: Moved to...
* util/rust-operators.h: ...here.

Signed-off-by: Abdul Rafey 
---
 gcc/rust/ast/rust-ast.cc   | 2 +-
 gcc/rust/ast/rust-expr.h   | 2 +-
 gcc/rust/hir/tree/rust-hir-expr.h  | 2 +-
 gcc/rust/rust-backend.h| 2 +-
 gcc/rust/util/rust-lang-item.h | 2 +-
 gcc/rust/{operator.h => util/rust-operators.h} | 0
 6 files changed, 5 insertions(+), 5 deletions(-)
 rename gcc/rust/{operator.h => util/rust-operators.h} (100%)

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 280f59ffb16..60a9f01e17f 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -25,7 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "rust-session-manager.h"
 #include "rust-lex.h"
 #include "rust-parse.h"
-#include "operator.h"
+#include "rust-operators.h"
 
 /* Compilation unit used for various AST-related functions that would make
  * the headers too long if they were defined inline and don't receive any
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 34bc6993ab6..3ed1885d5af 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -3,7 +3,7 @@
 
 #include "rust-ast.h"
 #include "rust-path.h"
-#include "operator.h"
+#include "rust-operators.h"
 
 namespace Rust {
 namespace AST {
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h 
b/gcc/rust/hir/tree/rust-hir-expr.h
index cc884420bef..bf103516800 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -23,7 +23,7 @@
 #include "rust-ast-full-decls.h"
 #include "rust-hir.h"
 #include "rust-hir-path.h"
-#include "operator.h"
+#include "rust-operators.h"
 
 namespace Rust {
 namespace HIR {
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 01c5fc40e8c..076104f3a40 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -26,7 +26,7 @@
 #include "rust-location.h"
 #include "rust-linemap.h"
 #include "rust-diagnostics.h"
-#include "operator.h"
+#include "util/rust-operators.h"
 #include "tree.h"
 
 // Pointers to these types are created by the backend, passed to the
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index ea0c91aa5f2..29c364bad61 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -17,7 +17,7 @@
 // .
 
 #include "rust-system.h"
-#include "operator.h"
+#include "rust-operators.h"
 
 namespace Rust {
 namespace Analysis {
diff --git a/gcc/rust/operator.h b/gcc/rust/util/rust-operators.h
similarity index 100%
rename from gcc/rust/operator.h
rename to gcc/rust/util/rust-operators.h
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 22/88] gccrs: fixed indentations in AST pretty expanded dump of trait

2023-04-05 Thread arthur . cohen
From: Abdul Rafey 

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): removed extra indentations in 
trait ast dump

Signed-off-by: Abdul Rafey 
---
 gcc/rust/ast/rust-ast-dump.cc | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 77e04b972dc..58eb35ad1db 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -1072,8 +1072,6 @@ Dump::visit (TypeBoundWhereClauseItem &item)
 void
 Dump::visit (Method &method)
 {
-  // FIXME: Do we really need to dump the indentation here?
-  stream << indentation;
   visit (method.get_visibility ());
   stream << "fn " << method.get_method_name () << '(';
 
@@ -1326,7 +1324,7 @@ void
 Dump::visit (TraitItemFunc &item)
 {
   auto func = item.get_trait_function_decl ();
-  stream << indentation << "fn " << func.get_identifier () << '(';
+  stream << "fn " << func.get_identifier () << '(';
 
   visit_items_joined_by_separator (func.get_function_params ());
 
@@ -1340,9 +1338,6 @@ Dump::visit (TraitItemMethod &item)
 {
   auto method = item.get_trait_method_decl ();
 
-  // FIXME: Do we really need to dump the indentation here?
-  stream << indentation;
-
   // FIXME: Can we have visibility here?
   // emit_visibility (method.get_visibility ());
   stream << "fn " << method.get_identifier () << '(';
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 27/88] gccrs: Improve GroupedPattern lowering

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit): Lower AST::GroupedPattern to its inner 
pattern.

Signed-off-by: Owen Avery 
---
 gcc/rust/hir/rust-ast-lower-pattern.cc | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc 
b/gcc/rust/hir/rust-ast-lower-pattern.cc
index 8ee3a979a33..a0fd8dded38 100644
--- a/gcc/rust/hir/rust-ast-lower-pattern.cc
+++ b/gcc/rust/hir/rust-ast-lower-pattern.cc
@@ -246,17 +246,7 @@ ASTLoweringPattern::visit (AST::RangePattern &pattern)
 void
 ASTLoweringPattern::visit (AST::GroupedPattern &pattern)
 {
-  auto crate_num = mappings->get_current_crate ();
-  Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (),
-mappings->get_next_hir_id (crate_num),
-UNKNOWN_LOCAL_DEFID);
-
-  HIR::Pattern *inner
-= ASTLoweringPattern::translate (pattern.get_pattern_in_parens ().get ());
-
-  translated
-= new HIR::GroupedPattern (mapping, std::unique_ptr (inner),
-  pattern.get_locus ());
+  pattern.get_pattern_in_parens ()->accept_vis (*this);
 }
 
 } // namespace HIR
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 26/88] gccrs: Move rust-buffered-queue.h to util folder #1766

2023-04-05 Thread arthur . cohen
From: MAHAD 

gcc/rust/ChangeLog:

* rust-buffered-queue.h: Moved to...
* util/rust-buffered-queue.h: ...here.

Signed-off-by: Muhammad Mahad 
---
 gcc/rust/{ => util}/rust-buffered-queue.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename gcc/rust/{ => util}/rust-buffered-queue.h (100%)

diff --git a/gcc/rust/rust-buffered-queue.h 
b/gcc/rust/util/rust-buffered-queue.h
similarity index 100%
rename from gcc/rust/rust-buffered-queue.h
rename to gcc/rust/util/rust-buffered-queue.h
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 35/88] gccrs: Add another test case for passing associated type-bounds

2023-04-05 Thread arthur . cohen
From: Philip Herron 

This demonstrates that this also works for custom algebraic data types too.

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-1720-2.rs: New test.

Signed-off-by: Philip Herron 
---
 .../rust/execute/torture/issue-1720-2.rs  | 30 +++
 1 file changed, 30 insertions(+)
 create mode 100644 gcc/testsuite/rust/execute/torture/issue-1720-2.rs

diff --git a/gcc/testsuite/rust/execute/torture/issue-1720-2.rs 
b/gcc/testsuite/rust/execute/torture/issue-1720-2.rs
new file mode 100644
index 000..35833dbb813
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/issue-1720-2.rs
@@ -0,0 +1,30 @@
+mod core {
+mod ops {
+#[lang = "add"]
+pub trait Add {
+type Output;
+
+fn add(self, rhs: Rhs) -> Self::Output;
+}
+}
+}
+
+struct Foo(i32);
+
+impl core::ops::Add for Foo {
+type Output = i32;
+
+fn add(self, rhs: Foo) -> Self::Output {
+self.0 + rhs.0
+}
+}
+
+pub fn bar>(a: T) -> i32 {
+a + a
+}
+
+pub fn main() -> i32 {
+let a = Foo(1);
+
+bar(a) - 2
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 37/88] gccrs: Refactor TyVar and TypeBoundPredicates

2023-04-05 Thread arthur . cohen
From: Philip Herron 

This extract these helpers into seperate files

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* Make-lang.in: update makefile
* typecheck/rust-tyty.cc (TyVar::TyVar): move to new file
(TyVar::get_tyty): likewise
(TyVar::get_implicit_infer_var): likewise
(TyVar::subst_covariant_var): likewise
(TyVar::clone): likewise
(TyVar::monomorphized_clone): likewise
(TyWithLocation::TyWithLocation): likewise
* typecheck/rust-tyty.h (class BaseType): cleanup
(class TypeBoundPredicate): move to its own file
(class TypeBoundPredicateItem): likewise
(class TypeBoundsMappings): likewise
(class TyVar): likewise
(class TyWithLocation): likewise
* typecheck/rust-tyty-bounds.h: New file.
* typecheck/rust-tyty-util.cc: New file.
* typecheck/rust-tyty-util.h: New file.
---
 gcc/rust/Make-lang.in |   1 +
 gcc/rust/typecheck/rust-tyty-bounds.h |  88 +++
 gcc/rust/typecheck/rust-tyty-util.cc  | 116 ++
 gcc/rust/typecheck/rust-tyty-util.h   |  69 +++
 gcc/rust/typecheck/rust-tyty.cc   |  90 
 gcc/rust/typecheck/rust-tyty.h|  90 +---
 6 files changed, 276 insertions(+), 178 deletions(-)
 create mode 100644 gcc/rust/typecheck/rust-tyty-bounds.h
 create mode 100644 gcc/rust/typecheck/rust-tyty-util.cc
 create mode 100644 gcc/rust/typecheck/rust-tyty-util.h

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index a0c5757592e..2aa61bcfb19 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -115,6 +115,7 @@ GRS_OBJS = \
 rust/rust-pub-restricted-visitor.o \
 rust/rust-privacy-reporter.o \
 rust/rust-tyty.o \
+rust/rust-tyty-util.o \
 rust/rust-tyty-call.o \
 rust/rust-tyctx.o \
 rust/rust-tyty-bounds.o \
diff --git a/gcc/rust/typecheck/rust-tyty-bounds.h 
b/gcc/rust/typecheck/rust-tyty-bounds.h
new file mode 100644
index 000..44839bd0b40
--- /dev/null
+++ b/gcc/rust/typecheck/rust-tyty-bounds.h
@@ -0,0 +1,88 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#ifndef RUST_TYTY_BOUNDS_H
+#define RUST_TYTY_BOUNDS_H
+
+#include "rust-location.h"
+
+namespace Rust {
+
+namespace Resolver {
+class TraitReference;
+class TraitItemReference;
+class AssociatedImplTrait;
+} // namespace Resolver
+
+namespace TyTy {
+
+class BaseType;
+class TypeBoundPredicate;
+class TypeBoundPredicateItem
+{
+public:
+  TypeBoundPredicateItem (const TypeBoundPredicate *parent,
+ const Resolver::TraitItemReference *trait_item_ref);
+
+  static TypeBoundPredicateItem error ();
+
+  bool is_error () const;
+
+  BaseType *get_tyty_for_receiver (const TyTy::BaseType *receiver);
+
+  const Resolver::TraitItemReference *get_raw_item () const;
+
+  bool needs_implementation () const;
+
+  const TypeBoundPredicate *get_parent () const;
+
+  Location get_locus () const;
+
+private:
+  const TypeBoundPredicate *parent;
+  const Resolver::TraitItemReference *trait_item_ref;
+};
+
+class TypeBoundsMappings
+{
+protected:
+  TypeBoundsMappings (std::vector specified_bounds);
+
+public:
+  std::vector &get_specified_bounds ();
+
+  const std::vector &get_specified_bounds () const;
+
+  size_t num_specified_bounds () const;
+
+  std::string raw_bounds_as_string () const;
+
+  std::string bounds_as_string () const;
+
+  std::string raw_bounds_as_name () const;
+
+protected:
+  void add_bound (TypeBoundPredicate predicate);
+
+  std::vector specified_bounds;
+};
+
+} // namespace TyTy
+} // namespace Rust
+
+#endif // RUST_TYTY_BOUNDS_H
diff --git a/gcc/rust/typecheck/rust-tyty-util.cc 
b/gcc/rust/typecheck/rust-tyty-util.cc
new file mode 100644
index 000..5037f68cb3f
--- /dev/null
+++ b/gcc/rust/typecheck/rust-tyty-util.cc
@@ -0,0 +1,116 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRA

[committed 28/88] gccrs: Remove HIR::GroupedPattern

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* backend/rust-compile-fnparam.h
(CompileFnParam::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-pattern.cc
(CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern 
visitor.
(CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-pattern.h
(CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern 
visitor.
(CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor.
(CompilePatternLet::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-resolve-path.h
(ResolvePathRef::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-var-decl.h
(CompileVarDecl::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-const-checker.h
(ConstChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-unsafe-checker.h
(UnsafeChecker::visit): Remove HIR::GroupedPattern visitor.
* hir/rust-hir-dump.cc (Dump::visit): Remove HIR::GroupedPattern 
visitor.
* hir/rust-hir-dump.h (Dump::visit): Remove HIR::GroupedPattern visitor.
* hir/tree/rust-hir-full-decls.h (class GroupedPattern): Remove class.
* hir/tree/rust-hir-full-test.cc (GroupedPattern::accept_vis): Remove 
method.
* hir/tree/rust-hir-pattern.h (class GroupedPattern): Remove class.
* hir/tree/rust-hir-visitor.h
(HIRFullVisitor::visit): Remove HIR::GroupedPattern visitor.
(HIRFullVisitorBase::visit): Remove HIR::GroupedPattern visitor.
(HIRPatternVisitor::visit): Remove HIR::GroupedPattern visitor.
* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor.
* typecheck/rust-hir-type-check-pattern.h
(TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor.

Signed-off-by: Owen Avery 
---
 gcc/rust/backend/rust-compile-fnparam.h   |  1 -
 gcc/rust/backend/rust-compile-pattern.cc  | 12 
 gcc/rust/backend/rust-compile-pattern.h   |  8 ---
 gcc/rust/backend/rust-compile-resolve-path.h  |  1 -
 gcc/rust/backend/rust-compile-var-decl.h  |  1 -
 gcc/rust/checks/errors/rust-const-checker.cc  |  4 --
 gcc/rust/checks/errors/rust-const-checker.h   |  1 -
 gcc/rust/checks/errors/rust-unsafe-checker.cc |  4 --
 gcc/rust/checks/errors/rust-unsafe-checker.h  |  1 -
 gcc/rust/hir/rust-hir-dump.cc |  3 -
 gcc/rust/hir/rust-hir-dump.h  |  1 -
 gcc/rust/hir/tree/rust-hir-full-decls.h   |  1 -
 gcc/rust/hir/tree/rust-hir-full-test.cc   | 12 
 gcc/rust/hir/tree/rust-hir-pattern.h  | 69 ---
 gcc/rust/hir/tree/rust-hir-visitor.h  |  3 -
 .../typecheck/rust-hir-type-check-pattern.cc  |  9 ---
 .../typecheck/rust-hir-type-check-pattern.h   |  1 -
 17 files changed, 132 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-fnparam.h 
b/gcc/rust/backend/rust-compile-fnparam.h
index 0d99814a6b3..10e8b67c140 100644
--- a/gcc/rust/backend/rust-compile-fnparam.h
+++ b/gcc/rust/backend/rust-compile-fnparam.h
@@ -39,7 +39,6 @@ public:
   void visit (HIR::TupleStructPattern &) override;
 
   // Empty visit for unused Pattern HIR nodes.
-  void visit (HIR::GroupedPattern &) override {}
   void visit (HIR::LiteralPattern &) override {}
   void visit (HIR::PathInExpression &) override {}
   void visit (HIR::QualifiedPathInExpression &) override {}
diff --git a/gcc/rust/backend/rust-compile-pattern.cc 
b/gcc/rust/backend/rust-compile-pattern.cc
index e13d6caf7e6..bad98be44d0 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -161,12 +161,6 @@ CompilePatternCaseLabelExpr::visit (HIR::RangePattern 
&pattern)
   case_label_expr = build_case_label (lower, upper, associated_case_label);
 }
 
-void
-CompilePatternCaseLabelExpr::visit (HIR::GroupedPattern &pattern)
-{
-  pattern.get_item ()->accept_vis (*this);
-}
-
 // setup the bindings
 
 void
@@ -335,12 +329,6 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern)
 }
 }
 
-void
-CompilePatternBindings::visit (HIR::GroupedPattern &pattern)
-{
-  pattern.get_item ()->accept_vis (*this);
-}
-
 void
 CompilePatternLet::visit (HIR::IdentifierPattern &pattern)
 {
diff --git a/gcc/rust/backend/rust-compile-pattern.h 
b/gcc/rust/backend/rust-compile-pattern.h
index 317a3451161..ddf5b14265e 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -38,7 +38,6 @@ public:
   void visit (HIR::TupleStructPattern &pattern) override;
   void visit (HIR::WildcardPattern &pattern) override;
   voi

[committed 14/88] gccrs: Do not crash on empty macros expand. Fixes #1712

2023-04-05 Thread arthur . cohen
From: Lyra 

This commit fixes a compiler crash when expanding an empty macro into an 
existing AST.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (transcribe_expression): Fix ICE when 
expanding
empty macros.

gcc/testsuite/ChangeLog:

* rust/compile/macro45.rs: New test.

Signed-off-by: Lyra Karenai 
---
 gcc/rust/expand/rust-macro-expand.cc  | 2 ++
 gcc/testsuite/rust/compile/macro45.rs | 7 +++
 2 files changed, 9 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/macro45.rs

diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index 9c3523e0515..bf914ee19e3 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -839,6 +839,8 @@ static AST::Fragment
 transcribe_expression (Parser &parser)
 {
   auto expr = parser.parse_expr ();
+  if (expr == nullptr)
+return AST::Fragment::create_error ();
 
   return AST::Fragment::complete ({std::move (expr)});
 }
diff --git a/gcc/testsuite/rust/compile/macro45.rs 
b/gcc/testsuite/rust/compile/macro45.rs
new file mode 100644
index 000..52dbcbb0016
--- /dev/null
+++ b/gcc/testsuite/rust/compile/macro45.rs
@@ -0,0 +1,7 @@
+macro_rules! empty {
+() => {}; // { dg-error "found unexpected token '\}' in null denotation" }
+}
+
+fn main() {
+let a = empty!();
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 05/88] gccrs: Implement declarative macro 2.0 parser

2023-04-05 Thread arthur . cohen
From: Raiki Tamura 

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (class MacroItem): Remove forward 
declaration.
* ast/rust-ast-full-test.cc (MacroRulesDefinition):
Rework MacroRulesDefinition class
* ast/rust-ast.h (class MacroItem): Remove abstract class.
* ast/rust-item.h (class MacroItem): Remove forward declaration.
* ast/rust-macro.h (class MacroItem): Likewise.
(class MacroRulesDefinition): Add MacroKind enum.
(class MacroInvocation): Fix inheritance.
* lex/rust-token.h: Token "macro" is now used.
* parse/rust-parse-impl.h (Parser::parse_item): Add handling for MACRO.
(Parser::parse_vis_item): Call into parse_decl_macro_def.
(Parser::parse_macro_item): Delete function.
(Parser::parse_macro_rules_def): Return MBE macros only.
(Parser::parse_decl_macro_def): New function.
(Parser::parse_stmt): Handle MACRO token.
(Parser::parse_stmt_or_expr_without_block): Call into 
parse_macro_rules_def.
* parse/rust-parse.h: Declare new function.

gcc/testsuite/ChangeLog:

* rust/compile/decl_macro1.rs: New test.
* rust/compile/decl_macro2.rs: New test.
* rust/compile/decl_macro3.rs: New test.
* rust/compile/decl_macro4.rs: New test.
* rust/compile/decl_macro5.rs: New test.
* rust/compile/decl_macro6.rs: New test.
* rust/compile/decl_macro7.rs: New test.
* rust/execute/torture/decl_macro1.rs: New test.
* rust/execute/torture/decl_macro2.rs: New test.
* rust/execute/torture/decl_macro3.rs: New test.
* rust/execute/torture/decl_macro4.rs: New test.

Signed-off-by: Raiki Tamura 
---
 gcc/rust/ast/rust-ast-full-decls.h|   1 -
 gcc/rust/ast/rust-ast-full-test.cc|   1 +
 gcc/rust/ast/rust-ast.h   |   5 -
 gcc/rust/ast/rust-item.h  |   2 -
 gcc/rust/ast/rust-macro.h |  65 +++--
 gcc/rust/lex/rust-token.h |   2 +-
 gcc/rust/parse/rust-parse-impl.h  | 229 +-
 gcc/rust/parse/rust-parse.h   |   3 +-
 gcc/testsuite/rust/compile/decl_macro1.rs |   2 +
 gcc/testsuite/rust/compile/decl_macro2.rs |   2 +
 gcc/testsuite/rust/compile/decl_macro3.rs |   4 +
 gcc/testsuite/rust/compile/decl_macro4.rs |   5 +
 gcc/testsuite/rust/compile/decl_macro5.rs |   5 +
 gcc/testsuite/rust/compile/decl_macro6.rs |   5 +
 gcc/testsuite/rust/compile/decl_macro7.rs |   4 +
 .../rust/execute/torture/decl_macro1.rs   |   8 +
 .../rust/execute/torture/decl_macro2.rs   |   8 +
 .../rust/execute/torture/decl_macro3.rs   |  15 ++
 .../rust/execute/torture/decl_macro4.rs   |  15 ++
 19 files changed, 301 insertions(+), 80 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/decl_macro1.rs
 create mode 100644 gcc/testsuite/rust/compile/decl_macro2.rs
 create mode 100644 gcc/testsuite/rust/compile/decl_macro3.rs
 create mode 100644 gcc/testsuite/rust/compile/decl_macro4.rs
 create mode 100644 gcc/testsuite/rust/compile/decl_macro5.rs
 create mode 100644 gcc/testsuite/rust/compile/decl_macro6.rs
 create mode 100644 gcc/testsuite/rust/compile/decl_macro7.rs
 create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro1.rs
 create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro2.rs
 create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro3.rs
 create mode 100644 gcc/testsuite/rust/execute/torture/decl_macro4.rs

diff --git a/gcc/rust/ast/rust-ast-full-decls.h 
b/gcc/rust/ast/rust-ast-full-decls.h
index 136a25ab9aa..58b12a1be0e 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -51,7 +51,6 @@ class Lifetime;
 class GenericParam;
 class LifetimeParam;
 class ConstGenericParam;
-class MacroItem;
 class TraitItem;
 class InherentImplItem;
 class TraitImplItem;
diff --git a/gcc/rust/ast/rust-ast-full-test.cc 
b/gcc/rust/ast/rust-ast-full-test.cc
index 4f593dcbd49..280f59ffb16 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -1284,6 +1284,7 @@ MacroRulesDefinition::as_string () const
   // get outer attrs
   str += append_attributes (outer_attrs, OUTER);
 
+  // TODO: deal with macro_2_0
   str += "macro_rules!";
 
   str += rule_name;
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index aa86f2f9826..5f18233eb0f 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -1350,11 +1350,6 @@ protected:
   }
 };
 
-// A macro item AST node - abstract base class
-class MacroItem : public Item
-{
-};
-
 // Item used in trait declarations - abstract base class
 class TraitItem
 {
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 7ea7b86562f..37ed2beabfc 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -4391,8 +4391,6 @@ protected:
   }
 };
 
-// Replaced with forward decls - defi

[committed 11/88] gccrs: Change how CompileVarDecl outputs Bvariable's

2023-04-05 Thread arthur . cohen
From: Owen Avery 

This allows patterns to declare multiple/no variables

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc 
(HIRCompileBase::compile_locals_for_block):
Allow patterns to declare zero or multiple variables.
* backend/rust-compile-var-decl.h: Change function declaration.

Signed-off-by: Owen Avery 
---
 gcc/rust/backend/rust-compile-base.cc|  4 +---
 gcc/rust/backend/rust-compile-var-decl.h | 26 ++--
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-base.cc 
b/gcc/rust/backend/rust-compile-base.cc
index 568abf9ca2c..c108661d983 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -457,9 +457,7 @@ HIRCompileBase::compile_locals_for_block (Context *ctx, 
Resolver::Rib &rib,
 
   // compile the local
   tree type = TyTyResolveCompile::compile (ctx, tyty);
-  Bvariable *compiled
-   = CompileVarDecl::compile (fndecl, type, pattern, ctx);
-  locals.push_back (compiled);
+  CompileVarDecl::compile (fndecl, type, pattern, locals, ctx);
 }
   return locals;
 }
diff --git a/gcc/rust/backend/rust-compile-var-decl.h 
b/gcc/rust/backend/rust-compile-var-decl.h
index 00146a42e9d..791ee9c1112 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -30,12 +30,11 @@ class CompileVarDecl : public HIRCompileBase, public 
HIR::HIRPatternVisitor
   using HIR::HIRPatternVisitor::visit;
 
 public:
-  static ::Bvariable *compile (tree fndecl, tree translated_type,
-  HIR::Pattern *pattern, Context *ctx)
+  static void compile (tree fndecl, tree translated_type, HIR::Pattern 
*pattern,
+  std::vector &locals, Context *ctx)
   {
-CompileVarDecl compiler (ctx, fndecl, translated_type);
+CompileVarDecl compiler (ctx, fndecl, translated_type, locals);
 pattern->accept_vis (compiler);
-return compiler.compiled_variable;
   }
 
   void visit (HIR::IdentifierPattern &pattern) override
@@ -43,26 +42,30 @@ public:
 if (!pattern.is_mut ())
   translated_type = ctx->get_backend ()->immutable_type (translated_type);
 
-compiled_variable
+Bvariable *var
   = ctx->get_backend ()->local_variable (fndecl, pattern.get_identifier (),
 translated_type, NULL /*decl_var*/,
 pattern.get_locus ());
 
 HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
-ctx->insert_var_decl (stmt_id, compiled_variable);
+ctx->insert_var_decl (stmt_id, var);
+
+locals.push_back (var);
   }
 
   void visit (HIR::WildcardPattern &pattern) override
   {
 translated_type = ctx->get_backend ()->immutable_type (translated_type);
 
-compiled_variable
+Bvariable *var
   = ctx->get_backend ()->local_variable (fndecl, "_", translated_type,
 NULL /*decl_var*/,
 pattern.get_locus ());
 
 HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
-ctx->insert_var_decl (stmt_id, compiled_variable);
+ctx->insert_var_decl (stmt_id, var);
+
+locals.push_back (var);
   }
 
   // Empty visit for unused Pattern HIR nodes.
@@ -78,15 +81,16 @@ public:
   void visit (HIR::TupleStructPattern &) override {}
 
 private:
-  CompileVarDecl (Context *ctx, tree fndecl, tree translated_type)
+  CompileVarDecl (Context *ctx, tree fndecl, tree translated_type,
+ std::vector &locals)
 : HIRCompileBase (ctx), fndecl (fndecl), translated_type (translated_type),
-  compiled_variable (ctx->get_backend ()->error_variable ())
+  locals (locals)
   {}
 
   tree fndecl;
   tree translated_type;
 
-  Bvariable *compiled_variable;
+  std::vector &locals;
 };
 
 } // namespace Compile
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 08/88] gccrs: Reuse TypeCheckPattern on LetStmt's

2023-04-05 Thread arthur . cohen
From: Owen Avery 

Update Rust type-checking to reuse TypeCheckPattern on HIR::LetStmt's.
This will unify the paths and improve error handling.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Cleanup 
LetStmt
type checking.

Signed-off-by: Owen Avery 
---
 gcc/rust/typecheck/rust-hir-type-check-stmt.cc | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc 
b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
index 437782e8102..956249a7607 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc
@@ -82,7 +82,7 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
 {
   infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ());
 
-  const HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
+  HIR::Pattern &stmt_pattern = *stmt.get_pattern ();
   TyTy::BaseType *init_expr_ty = nullptr;
   Location init_expr_locus;
   if (stmt.has_init_expr ())
@@ -111,27 +111,25 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt)
 TyTy::TyWithLocation (specified_ty, specified_ty_locus),
 TyTy::TyWithLocation (init_expr_ty, init_expr_locus),
 stmt.get_locus ());
-  context->insert_type (stmt_pattern.get_pattern_mappings (), 
specified_ty);
+  TypeCheckPattern::Resolve (&stmt_pattern, specified_ty);
 }
   else
 {
   // let x:i32;
   if (specified_ty != nullptr)
{
- context->insert_type (stmt_pattern.get_pattern_mappings (),
-   specified_ty);
+ TypeCheckPattern::Resolve (&stmt_pattern, specified_ty);
}
   // let x = 123;
   else if (init_expr_ty != nullptr)
{
- context->insert_type (stmt_pattern.get_pattern_mappings (),
-   init_expr_ty);
+ TypeCheckPattern::Resolve (&stmt_pattern, init_expr_ty);
}
   // let x;
   else
{
- context->insert_type (
-   stmt_pattern.get_pattern_mappings (),
+ TypeCheckPattern::Resolve (
+   &stmt_pattern,
new TyTy::InferType (
  stmt_pattern.get_pattern_mappings ().get_hirid (),
  TyTy::InferType::InferTypeKind::GENERAL, stmt.get_locus ()));
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 23/88] gccrs: macro: Allow builtin `MacroInvocation`s within the AST

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* ast/rust-macro.h (enum class): Add `BuiltinMacro` enum class.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Mention
switching on `macro.kind` once builtin macro invocations are properly
handled.
* parse/rust-parse-impl.h (Parser::parse_macro_invocation): Switch to 
new MacroInvocation
API.
(Parser::parse_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.
---
 gcc/rust/ast/rust-macro.h | 110 ++
 gcc/rust/expand/rust-attribute-visitor.cc |   2 +
 gcc/rust/parse/rust-parse-impl.h  |  70 +++---
 3 files changed, 126 insertions(+), 56 deletions(-)

diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 4226c6919ff..68dd7d660d3 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -578,8 +578,30 @@ protected:
   }
 };
 
+/**
+ * All builtin macros possible
+ */
+enum class BuiltinMacro
+{
+  Assert,
+  File,
+  Line,
+  Column,
+  IncludeBytes,
+  IncludeStr,
+  CompileError,
+  Concat,
+  Env,
+  Cfg,
+  Include
+};
+
 /* AST node of a macro invocation, which is replaced by the macro result at
- * compile time */
+ * compile time. This is technically a sum-type/tagged-union, which represents
+ * both classic macro invocations and builtin macro invocations. Regular macro
+ * invocations are expanded lazily, but builtin macro invocations need to be
+ * expanded eagerly, hence the differentiation.
+ */
 class MacroInvocation : public TypeNoBounds,
public Pattern,
public Item,
@@ -589,26 +611,47 @@ class MacroInvocation : public TypeNoBounds,
public ExternalItem,
public ExprWithoutBlock
 {
-  std::vector outer_attrs;
-  MacroInvocData invoc_data;
-  Location locus;
-
-  // Important for when we actually expand the macro
-  bool is_semi_coloned;
-
-  NodeId node_id;
-
 public:
+  enum class InvocKind
+  {
+Regular,
+Builtin,
+  };
+
   std::string as_string () const override;
 
-  MacroInvocation (MacroInvocData invoc_data,
-  std::vector outer_attrs, Location locus,
-  bool is_semi_coloned = false)
-: outer_attrs (std::move (outer_attrs)),
-  invoc_data (std::move (invoc_data)), locus (locus),
-  is_semi_coloned (is_semi_coloned),
-  node_id (Analysis::Mappings::get ()->get_next_node_id ())
-  {}
+  /**
+   * The default constructor you should use. Whenever we parse a macro call, we
+   * cannot possibly know whether or not this call refers to a builtin macro or
+   * a regular macro. With name resolution and scopes and nested macro calls,
+   * this is literally impossible. Hence, always start by creating a `Regular`
+   * MacroInvocation which will then (maybe!) become a `Builtin` macro
+   * invocation in the expander.
+   */
+  static std::unique_ptr
+  Regular (MacroInvocData invoc_data, std::vector outer_attrs,
+  Location locus, bool is_semi_coloned = false)
+  {
+return std::unique_ptr (
+  new MacroInvocation (InvocKind::Regular, Optional::none (),
+  invoc_data, outer_attrs, locus, is_semi_coloned));
+  }
+
+  /**
+   * Create a builtin macro invocation. This can only be done after macro
+   * name-resolution and within the macro expander, so unless you're modifying
+   * these visitors, you probably do not want to use this function.
+   */
+  static std::unique_ptr
+  Builtin (BuiltinMacro kind, MacroInvocData invoc_data,
+  std::vector outer_attrs, Location locus,
+  bool is_semi_coloned = false)
+  {
+return std::unique_ptr (
+  new MacroInvocation (InvocKind::Builtin,
+  Optional::some (kind), invoc_data,
+  outer_attrs, locus, is_semi_coloned));
+  }
 
   Location get_locus () const override final { return locus; }
 
@@ -642,6 +685,37 @@ public:
 
   bool has_semicolon () const { return is_semi_coloned; }
 
+  InvocKind get_kind () const { return kind; }
+  Optional get_builtin_kind () const { return builtin_kind; }
+
+private:
+  /* Full constructor */
+  MacroInvocation (InvocKind kind, Optional builtin_kind,
+  MacroInvocData invoc_data,
+  std::vector outer_attrs, Location locus,
+  bool is_semi_coloned)
+: outer_attrs (std::move (outer_attrs)), locus (locus),
+  node_id (Analysis::Mappings::get ()->get_next_node_id ()),
+  invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned),
+  kind (kind), builtin_kind (builtin_kind)
+  {}
+
+  std::vector outer_attrs;
+  Location locus;
+  NodeId node_id;
+
+  /* The data given to the macro invocation */
+  MacroInvocData invoc_data;
+
+  /* Important for when we actually expand the macro */
+  bool is_semi_coloned;
+
+  /* Is this a builtin macro or a regular macro */
+  InvocKind kind;
+
+  /* If it is a 

[committed 48/88] gccrs: Add missing param subst callback

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: add missing callback
---
 gcc/rust/typecheck/rust-tyty-subst.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index 0e181efb359..7f5bb22687d 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -141,6 +141,7 @@ SubstitutionParamMapping::fill_param_ty (
bound.handle_substitions (subst_mappings);
 
   param->set_ty_ref (type.get_ref ());
+  subst_mappings.on_param_subst (*param, arg);
 }
 
   return true;
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 38/88] gccrs: Refactor SubstitutionRef base class into its own CC file

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* Make-lang.in: update the makefile
* typecheck/rust-tyty.cc (SubstitutionParamMapping::need_substitution): 
likewise
(SubstitutionParamMapping::override_context): likewise
(SubstitutionRef::get_mappings_from_generic_args): likewise
(SubstitutionRef::infer_substitions): likewise
(SubstitutionRef::are_mappings_bound): likewise
(SubstitutionRef::solve_missing_mappings_from_this): likewise
(SubstitutionRef::monomorphize): likewise
* typecheck/rust-tyty.h (class SubstitutionParamMapping): likewise
(class SubstitutionArg): likewise
(std::functionhttp://www.gnu.org/licenses/>.
+
+#include "rust-tyty-subst.h"
+#include "rust-hir-full.h"
+#include "rust-tyty.h"
+#include "rust-hir-type-check.h"
+#include "rust-substitution-mapper.h"
+#include "rust-hir-type-check-type.h"
+
+namespace Rust {
+namespace TyTy {
+
+SubstitutionParamMapping::SubstitutionParamMapping (
+  const HIR::TypeParam &generic, ParamType *param)
+  : generic (generic), param (param)
+{}
+
+SubstitutionParamMapping::SubstitutionParamMapping (
+  const SubstitutionParamMapping &other)
+  : generic (other.generic), param (other.param)
+{}
+
+std::string
+SubstitutionParamMapping::as_string () const
+{
+  if (param == nullptr)
+return "nullptr";
+
+  return param->get_name ();
+}
+
+SubstitutionParamMapping
+SubstitutionParamMapping::clone () const
+{
+  return SubstitutionParamMapping (generic,
+  static_cast (param->clone ()));
+}
+
+ParamType *
+SubstitutionParamMapping::get_param_ty ()
+{
+  return param;
+}
+
+const ParamType *
+SubstitutionParamMapping::get_param_ty () const
+{
+  return param;
+}
+
+const HIR::TypeParam &
+SubstitutionParamMapping::get_generic_param ()
+{
+  return generic;
+};
+
+bool
+SubstitutionParamMapping::needs_substitution () const
+{
+  return !(get_param_ty ()->is_concrete ());
+}
+
+Location
+SubstitutionParamMapping::get_param_locus () const
+{
+  return generic.get_locus ();
+}
+
+bool
+SubstitutionParamMapping::param_has_default_ty () const
+{
+  return generic.has_type ();
+}
+
+BaseType *
+SubstitutionParamMapping::get_default_ty () const
+{
+  TyVar var (generic.get_type_mappings ().get_hirid ());
+  return var.get_tyty ();
+}
+
+bool
+SubstitutionParamMapping::need_substitution () const
+{
+  if (!param->can_resolve ())
+return true;
+
+  auto resolved = param->resolve ();
+  return !resolved->is_concrete ();
+}
+
+bool
+SubstitutionParamMapping::fill_param_ty (
+  SubstitutionArgumentMappings &subst_mappings, Location locus)
+{
+  SubstitutionArg arg = SubstitutionArg::error ();
+  bool ok = subst_mappings.get_argument_for_symbol (get_param_ty (), &arg);
+  if (!ok)
+return true;
+
+  TyTy::BaseType &type = *arg.get_tyty ();
+  if (type.get_kind () == TyTy::TypeKind::INFER)
+{
+  type.inherit_bounds (*param);
+}
+  else
+{
+  if (!param->bounds_compatible (type, locus, true))
+   return false;
+}
+
+  if (type.get_kind () == TypeKind::PARAM)
+{
+  // delete param;
+  param = static_cast (type.clone ());
+}
+  else
+{
+  // check the substitution is compatible with bounds
+  if (!param->bounds_compatible (type, locus, true))
+   return false;
+
+  // recursively pass this down to all HRTB's
+  for (auto &bound : param->get_specified_bounds ())
+   bound.handle_substitions (subst_mappings);
+
+  param->set_ty_ref (type.get_ref ());
+}
+
+  return true;
+}
+
+void
+SubstitutionParamMapping::override_context ()
+{
+  if (!param->can_resolve ())
+return;
+
+  auto mappings = Analysis::Mappings::get ();
+  auto context = Resolver::TypeCheckContext::get ();
+
+  context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (),
+  UNKNOWN_NODEID,
+  param->get_ref (),
+  UNKNOWN_LOCAL_DEFID),
+   param->resolve ());
+}
+
+SubstitutionArg::SubstitutionArg (const SubstitutionParamMapping *param,
+ BaseType *argument)
+  : param (param), argument (argument)
+{}
+
+SubstitutionArg::SubstitutionArg (const SubstitutionArg &other)
+  : param (other.param), argument (other.argument)
+{}
+
+SubstitutionArg &
+SubstitutionArg::operator= (const SubstitutionArg &other)
+{
+  param = other.param;
+  argument = other.argument;
+  return *this;
+}
+
+BaseType *
+SubstitutionArg::get_tyty ()
+{
+  return argument;
+}
+
+const BaseType *
+SubstitutionArg::get_tyty () const
+{
+  return argument;
+}
+
+const SubstitutionParamMapping *
+SubstitutionArg::get_param_mapping () const
+{
+  return param;
+}
+
+SubstitutionArg
+SubstitutionArg::error ()
+{
+  return SubstitutionArg (nullptr, nullptr);
+}
+
+bool
+SubstitutionArg::is_error () const
+{
+  return par

[committed 36/88] gccrs: Move TypePredicateItem impl out of the header

2023-04-05 Thread arthur . cohen
From: Philip Herron 

This moves the implementation code out of the header and into its
respective cc file.

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeBoundPredicateItem::error): 
refactor
(TypeBoundPredicateItem::is_error): likewise
(TypeBoundPredicateItem::get_parent): likewise
* typecheck/rust-tyty.h: Move the implementation for the above
---
 gcc/rust/typecheck/rust-tyty-bounds.cc | 24 
 gcc/rust/typecheck/rust-tyty.h | 16 
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc 
b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 30f7b0d02e3..e7eb9a760f5 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -364,6 +364,30 @@ TypeBoundPredicate::lookup_associated_item (const 
std::string &search) const
   return TypeBoundPredicateItem (this, trait_item_ref);
 }
 
+TypeBoundPredicateItem::TypeBoundPredicateItem (
+  const TypeBoundPredicate *parent,
+  const Resolver::TraitItemReference *trait_item_ref)
+  : parent (parent), trait_item_ref (trait_item_ref)
+{}
+
+TypeBoundPredicateItem
+TypeBoundPredicateItem::error ()
+{
+  return TypeBoundPredicateItem (nullptr, nullptr);
+}
+
+bool
+TypeBoundPredicateItem::is_error () const
+{
+  return parent == nullptr || trait_item_ref == nullptr;
+}
+
+const TypeBoundPredicate *
+TypeBoundPredicateItem::get_parent () const
+{
+  return parent;
+}
+
 TypeBoundPredicateItem
 TypeBoundPredicate::lookup_associated_item (
   const Resolver::TraitItemReference *ref) const
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 20a243fe980..7d32ed59494 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -82,19 +82,11 @@ class TypeBoundPredicateItem
 {
 public:
   TypeBoundPredicateItem (const TypeBoundPredicate *parent,
- const Resolver::TraitItemReference *trait_item_ref)
-: parent (parent), trait_item_ref (trait_item_ref)
-  {}
+ const Resolver::TraitItemReference *trait_item_ref);
 
-  static TypeBoundPredicateItem error ()
-  {
-return TypeBoundPredicateItem (nullptr, nullptr);
-  }
+  static TypeBoundPredicateItem error ();
 
-  bool is_error () const
-  {
-return parent == nullptr || trait_item_ref == nullptr;
-  }
+  bool is_error () const;
 
   BaseType *get_tyty_for_receiver (const TyTy::BaseType *receiver);
 
@@ -102,7 +94,7 @@ public:
 
   bool needs_implementation () const;
 
-  const TypeBoundPredicate *get_parent () const { return parent; }
+  const TypeBoundPredicate *get_parent () const;
 
   Location get_locus () const;
 
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 21/88] gccrs: fixed compiler error message on wildcard pattern within expression

2023-04-05 Thread arthur . cohen
From: Abdul Rafey 

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::null_denotation): Add proper error
when seeing wildcard var on right side of assignment.

gcc/testsuite/ChangeLog:

* rust/compile/issue-867.rs: New test.

Signed-off-by: Abdul Rafey 
---
 gcc/rust/parse/rust-parse-impl.h| 6 ++
 gcc/testsuite/rust/compile/issue-867.rs | 8 
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-867.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index d71bafded63..af749ca9200 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -13021,6 +13021,12 @@ Parser::null_denotation 
(const_TokenPtr tok,
 case UNSAFE:
   return parse_unsafe_block_expr (std::move (outer_attrs),
  tok->get_locus ());
+case UNDERSCORE:
+  add_error (
+   Error (tok->get_locus (),
+  "use of %qs is not allowed on the right-side of an assignment",
+  tok->get_token_description ()));
+  return nullptr;
 default:
   if (!restrictions.expr_can_be_null)
add_error (Error (tok->get_locus (),
diff --git a/gcc/testsuite/rust/compile/issue-867.rs 
b/gcc/testsuite/rust/compile/issue-867.rs
new file mode 100644
index 000..8e120685c1a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-867.rs
@@ -0,0 +1,8 @@
+fn main() {
+let _ = 42;
+let a = _ + 123; // { dg-error "use of '_' is not allowed on the 
right-side of an assignment" }
+ // { dg-error {failed to parse expression in let 
statement} "" { target *-*-* } .-1  }
+ // { dg-error {failed to parse statement or expression 
without block in block expression} "" { target *-*-* } .-2 }
+ // { dg-error {unrecognised token '\}' for start of item} 
"" { target *-*-* } .+2 }
+ // { dg-error {failed to parse item in crate} "" { target 
*-*-* } .+1 }
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 32/88] gccrs: parser: Fix parsing of closure param list

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_closure_expr): Advance tokens
properly when parsing closure param list.

gcc/testsuite/ChangeLog:

* rust/compile/closure_move_expr.rs: New test.
---
 gcc/rust/parse/rust-parse-impl.h| 2 ++
 gcc/testsuite/rust/compile/closure_move_expr.rs | 9 +
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/closure_move_expr.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 3610790815c..4ceb978f7f4 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -7592,6 +7592,7 @@ Parser::parse_closure_expr 
(AST::AttrVec outer_attrs)
 case PIPE:
   // actually may have parameters
   lexer.skip_token ();
+  t = lexer.peek_token ();
 
   while (t->get_id () != PIPE)
{
@@ -7608,6 +7609,7 @@ Parser::parse_closure_expr 
(AST::AttrVec outer_attrs)
 
  if (lexer.peek_token ()->get_id () != COMMA)
{
+ lexer.skip_token ();
  // not an error but means param list is done
  break;
}
diff --git a/gcc/testsuite/rust/compile/closure_move_expr.rs 
b/gcc/testsuite/rust/compile/closure_move_expr.rs
new file mode 100644
index 000..780c316e0af
--- /dev/null
+++ b/gcc/testsuite/rust/compile/closure_move_expr.rs
@@ -0,0 +1,9 @@
+// { dg-additional-options "-fsyntax-only" }
+
+fn foo() {
+move |l: u32, r: u32| l + r
+}
+
+fn foo2() {
+|l: u32, r: u32| l + r
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 10/88] gccrs: diagnostics: Add underline for tokens in diagnostics.

2023-04-05 Thread arthur . cohen
From: mxlol233 

Currently, the diagnostics only point to the corresponding token's
start position by carets, and lack of underlines for full token.  This
commit add support for such underlines in diagnostics by encoding range
information in location_t.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::build_token): Make location enclose entire 
token.
(Lexer::parse_byte_char): Likewise.
(Lexer::parse_byte_string): Likewise.
(Lexer::parse_raw_byte_string): Likewise.
(Lexer::parse_raw_identifier): Likewise.
(Lexer::parse_string): Likewise.
(Lexer::parse_identifier_or_keyword): Likewise.
(Lexer::parse_raw_string): Likewise.
(Lexer::parse_non_decimal_int_literal): Likewise.
(Lexer::parse_decimal_int_or_float): Likewise.
(Lexer::parse_char_or_lifetime): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/diagnostic_underline.rs: New test.

Signed-off-by: Xiao Ma 
---
 gcc/rust/lex/rust-lex.cc  | 57 +++
 .../rust/compile/diagnostic_underline.rs  | 15 +
 2 files changed, 72 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/diagnostic_underline.rs

diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index ac7ced540e6..9967cecb2e2 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -447,6 +447,7 @@ Lexer::build_token ()
  // match arm arrow
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (MATCH_ARROW, loc);
}
@@ -455,6 +456,7 @@ Lexer::build_token ()
  // equality operator
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (EQUAL_EQUAL, loc);
}
@@ -473,6 +475,7 @@ Lexer::build_token ()
  // return type specifier
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (RETURN_TYPE, loc);
}
@@ -481,6 +484,7 @@ Lexer::build_token ()
  // minus-assign
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (MINUS_EQ, loc);
}
@@ -496,6 +500,7 @@ Lexer::build_token ()
  // add-assign
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (PLUS_EQ, loc);
}
@@ -517,6 +522,7 @@ Lexer::build_token ()
  // multiplication-assign
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (ASTERISK_EQ, loc);
}
@@ -535,6 +541,7 @@ Lexer::build_token ()
  // division-assign
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (DIV_EQ, loc);
}
@@ -602,6 +609,8 @@ Lexer::build_token ()
  start_line (current_line, max_column_hint);
 
  str.shrink_to_fit ();
+
+ loc += str.size () - 1;
  if (is_inner)
return Token::make_inner_doc_comment (loc, std::move (str));
  else
@@ -756,6 +765,8 @@ Lexer::build_token ()
}
 
  str.shrink_to_fit ();
+
+ loc += str.size () - 1;
  if (is_inner)
return Token::make_inner_doc_comment (loc, std::move (str));
  else
@@ -773,6 +784,7 @@ Lexer::build_token ()
  // modulo-assign
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (PERCENT_EQ, loc);
}
@@ -788,6 +800,7 @@ Lexer::build_token ()
  // xor-assign?
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (CARET_EQ, loc);
}
@@ -805,6 +818,7 @@ Lexer::build_token ()
  // left-shift assign
  skip_input (1);
  current_column += 3;
+ loc += 2;
 
  return Token::make (LEFT_SHIFT_EQ, loc);
}
@@ -813,6 +827,7 @@ Lexer::build_token ()
  // left-shift
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (LEFT_SHIFT, loc);
}
@@ -822,6 +837,7 @@ Lexer::build_token ()
  // smaller than or equal to
  skip_input ();
  current_column += 2;
+ loc += 1;
 
  return Token::make (LESS_OR_EQUAL, loc);
}
@@ -840,6 +856,7 @@ Lexer::build_token ()
  // right-shift-assign
  skip_input (1);
  current_column += 3;
+ loc += 2;
 
  return Token::make (RIGHT_SHIFT_EQ

[committed 04/88] gccrs: rust: add bound parsing in parse_generic_arg.

2023-04-05 Thread arthur . cohen
From: mxlol233 

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_generic_arg): Add proper bound 
parsing.

gcc/testsuite/ChangeLog:

* rust/compile/bounds.rs: New test.

Signed-off-by: Xiao Ma 
---
 gcc/rust/parse/rust-parse-impl.h | 17 +
 gcc/testsuite/rust/compile/bounds.rs | 10 ++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/bounds.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index cbd40efcc9b..959e0338a10 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6198,6 +6198,23 @@ Parser::parse_generic_arg ()
else
  return AST::GenericArg::create_error ();
  }
+   else if (next_tok->get_id () == COLON)
+ {
+   lexer.skip_token (); // skip ident
+   lexer.skip_token (); // skip colon
+
+   auto tok = lexer.peek_token ();
+   std::vector> bounds
+ = parse_type_param_bounds ();
+
+   auto type = std::unique_ptr (
+ new AST::TraitObjectType (std::move (bounds), tok->get_locus (),
+   false));
+   if (type)
+ return AST::GenericArg::create_type (std::move (type));
+   else
+ return AST::GenericArg::create_error ();
+ }
lexer.skip_token ();
return AST::GenericArg::create_ambiguous (tok->get_str (),
  tok->get_locus ());
diff --git a/gcc/testsuite/rust/compile/bounds.rs 
b/gcc/testsuite/rust/compile/bounds.rs
new file mode 100644
index 000..ecb10d81f65
--- /dev/null
+++ b/gcc/testsuite/rust/compile/bounds.rs
@@ -0,0 +1,10 @@
+trait Foo {
+type Bar;
+}
+
+trait Copy {}
+
+
+fn c>() where F::Bar: Copy { // { dg-warning "function is 
never used: 'c'" }
+}
+
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 47/88] gccrs: Clear the substitution callbacks when copying ArgumentMappings

2023-04-05 Thread arthur . cohen
From: Philip Herron 

When we set the callback on substitutions this is not safe to be copied
around since we store the used argument mappings and can reuse them in
different contexts. This clears the callback on copy's to make it safer.

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: update copy constructors
---
 gcc/rust/typecheck/rust-tyty-subst.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index a5d738744fc..0e181efb359 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -241,7 +241,7 @@ SubstitutionArgumentMappings::SubstitutionArgumentMappings (
 SubstitutionArgumentMappings::SubstitutionArgumentMappings (
   const SubstitutionArgumentMappings &other)
   : mappings (other.mappings), binding_args (other.binding_args),
-locus (other.locus), param_subst_cb (other.param_subst_cb),
+locus (other.locus), param_subst_cb (nullptr),
 trait_item_flag (other.trait_item_flag)
 {}
 
@@ -252,7 +252,7 @@ SubstitutionArgumentMappings::operator= (
   mappings = other.mappings;
   binding_args = other.binding_args;
   locus = other.locus;
-  param_subst_cb = other.param_subst_cb;
+  param_subst_cb = nullptr;
   trait_item_flag = other.trait_item_flag;
 
   return *this;
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 30/88] gccrs: Implement lowering ReferencePattern from AST to HIR

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* ast/rust-pattern.h:
(ReferencePattern::is_double_reference): Add method.
(ReferencePattern::get_is_mut): Add method.
* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit): Add ReferencePattern visitor.
* hir/rust-ast-lower-pattern.h:
(ASTLoweringPattern::visit): Add ReferencePattern visitor.

Signed-off-by: Owen Avery 
---
 gcc/rust/ast/rust-pattern.h|  4 
 gcc/rust/hir/rust-ast-lower-pattern.cc | 29 ++
 gcc/rust/hir/rust-ast-lower-pattern.h  |  1 +
 3 files changed, 34 insertions(+)

diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index c86bdf6f820..cf5d2ead10d 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -469,6 +469,10 @@ public:
 return pattern;
   }
 
+  bool is_double_reference () const { return has_two_amps; }
+
+  bool get_is_mut () const { return is_mut; }
+
   NodeId get_node_id () const { return node_id; }
 
   NodeId get_pattern_node_id () const override final { return node_id; }
diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc 
b/gcc/rust/hir/rust-ast-lower-pattern.cc
index a0fd8dded38..1961c740624 100644
--- a/gcc/rust/hir/rust-ast-lower-pattern.cc
+++ b/gcc/rust/hir/rust-ast-lower-pattern.cc
@@ -249,5 +249,34 @@ ASTLoweringPattern::visit (AST::GroupedPattern &pattern)
   pattern.get_pattern_in_parens ()->accept_vis (*this);
 }
 
+void
+ASTLoweringPattern::visit (AST::ReferencePattern &pattern)
+{
+  auto crate_num = mappings->get_current_crate ();
+  Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (),
+mappings->get_next_hir_id (crate_num),
+UNKNOWN_LOCAL_DEFID);
+
+  HIR::Pattern *inner
+= ASTLoweringPattern::translate (pattern.get_referenced_pattern ().get ());
+
+  translated
+= new HIR::ReferencePattern (mapping, std::unique_ptr 
(inner),
+pattern.get_is_mut () ? Mutability::Mut
+  : Mutability::Imm,
+pattern.get_locus ());
+
+  if (pattern.is_double_reference ())
+{
+  Analysis::NodeMapping mapping2 (crate_num, pattern.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+  translated
+   = new HIR::ReferencePattern (mapping2,
+std::unique_ptr (translated),
+Mutability::Imm, pattern.get_locus ());
+}
+}
+
 } // namespace HIR
 } // namespace Rust
diff --git a/gcc/rust/hir/rust-ast-lower-pattern.h 
b/gcc/rust/hir/rust-ast-lower-pattern.h
index 0075e27e9c0..2d175a25cb4 100644
--- a/gcc/rust/hir/rust-ast-lower-pattern.h
+++ b/gcc/rust/hir/rust-ast-lower-pattern.h
@@ -40,6 +40,7 @@ public:
   void visit (AST::LiteralPattern &pattern) override;
   void visit (AST::RangePattern &pattern) override;
   void visit (AST::GroupedPattern &pattern) override;
+  void visit (AST::ReferencePattern &pattern) override;
 
 private:
   ASTLoweringPattern ();
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 19/88] gccrs: Rename file rust-ast-full-test.cc to rust-ast.cc

2023-04-05 Thread arthur . cohen
From: Parthib 

gcc/rust/ChangeLog:

* Make-lang.in: Rename object file.
* ast/rust-ast-full-test.cc: Moved to...
* ast/rust-ast.cc: ...here.
---
 gcc/rust/Make-lang.in   | 2 +-
 gcc/rust/ast/{rust-ast-full-test.cc => rust-ast.cc} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename gcc/rust/ast/{rust-ast-full-test.cc => rust-ast.cc} (100%)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index dddc70a26ec..87f3ba66eba 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -73,7 +73,7 @@ GRS_OBJS = \
 rust/rust-lex.o \
 rust/rust-cfg-parser.o \
 rust/rust-parse.o \
-rust/rust-ast-full-test.o \
+rust/rust-ast.o \
 rust/rust-ast-fragment.o \
 rust/rust-ast-dump.o \
 rust/rust-hir-dump.o \
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast.cc
similarity index 100%
rename from gcc/rust/ast/rust-ast-full-test.cc
rename to gcc/rust/ast/rust-ast.cc
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 18/88] gccrs: Added missing GroupedPattern visitors for code generation

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): 
Add proper
visitor.
(CompilePatternBindings::visit): Likewise.
* backend/rust-compile-pattern.h: Declare them.

Signed-off-by: Owen Avery 
---
 gcc/rust/backend/rust-compile-pattern.cc | 12 
 gcc/rust/backend/rust-compile-pattern.h  |  4 ++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-pattern.cc 
b/gcc/rust/backend/rust-compile-pattern.cc
index fc70d4ba58d..9218b815dd8 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -161,6 +161,12 @@ CompilePatternCaseLabelExpr::visit (HIR::RangePattern 
&pattern)
   case_label_expr = build_case_label (lower, upper, associated_case_label);
 }
 
+void
+CompilePatternCaseLabelExpr::visit (HIR::GroupedPattern &pattern)
+{
+  pattern.get_item ()->accept_vis (*this);
+}
+
 // setup the bindings
 
 void
@@ -329,5 +335,11 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern)
 }
 }
 
+void
+CompilePatternBindings::visit (HIR::GroupedPattern &pattern)
+{
+  pattern.get_item ()->accept_vis (*this);
+}
+
 } // namespace Compile
 } // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-pattern.h 
b/gcc/rust/backend/rust-compile-pattern.h
index 22812a45405..43334affca7 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -38,9 +38,9 @@ public:
   void visit (HIR::TupleStructPattern &pattern) override;
   void visit (HIR::WildcardPattern &pattern) override;
   void visit (HIR::RangePattern &pattern) override;
+  void visit (HIR::GroupedPattern &pattern) override;
 
   // Empty visit for unused Pattern HIR nodes.
-  void visit (HIR::GroupedPattern &) override {}
   void visit (HIR::IdentifierPattern &) override {}
   void visit (HIR::LiteralPattern &) override;
   void visit (HIR::QualifiedPathInExpression &) override {}
@@ -70,9 +70,9 @@ public:
 
   void visit (HIR::StructPattern &pattern) override;
   void visit (HIR::TupleStructPattern &pattern) override;
+  void visit (HIR::GroupedPattern &) override;
 
   // Empty visit for unused Pattern HIR nodes.
-  void visit (HIR::GroupedPattern &) override {}
   void visit (HIR::IdentifierPattern &) override {}
   void visit (HIR::LiteralPattern &) override {}
   void visit (HIR::PathInExpression &) override {}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 17/88] gccrs: Add type resolution for grouped patterns

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): 
Add proper
visitor.

Signed-off-by: Owen Avery 
---
 gcc/rust/typecheck/rust-hir-type-check-pattern.cc | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc 
b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index b017a851b5d..393f4158003 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -387,10 +387,12 @@ TypeCheckPattern::visit (HIR::IdentifierPattern &)
 }
 
 void
-TypeCheckPattern::visit (HIR::GroupedPattern &)
+TypeCheckPattern::visit (HIR::GroupedPattern &pattern)
 {
-  // TODO
-  gcc_unreachable ();
+  TyTy::BaseType *inner_ty
+= TypeCheckPattern::Resolve (pattern.get_item ().get (), parent);
+  infered = inner_ty->clone ();
+  infered->set_ref (pattern.get_pattern_mappings ().get_hirid ());
 }
 
 void
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 13/88] gccrs: Support GroupedPattern during name resolution

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.h: Support GroupedPattern properly.

Signed-off-by: Owen Avery 
---
 gcc/rust/resolve/rust-ast-resolve-pattern.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h 
b/gcc/rust/resolve/rust-ast-resolve-pattern.h
index 5f2b7293cf2..3e74f0a4cc6 100644
--- a/gcc/rust/resolve/rust-ast-resolve-pattern.h
+++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h
@@ -77,6 +77,11 @@ public:
   pattern.get_node_id (), pattern.get_locus (), type);
   }
 
+  void visit (AST::GroupedPattern &pattern) override
+  {
+pattern.get_pattern_in_parens ()->accept_vis (*this);
+  }
+
   // cases in a match expression
   void visit (AST::PathInExpression &pattern) override;
 
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 09/88] gccrs: Add get_locus function for abstract class MetaItemInner.

2023-04-05 Thread arthur . cohen
From: mxlol233 

This commit adds virtual function get_locus to base class MetaItemInner,
which is helpful when we need to print  diagnostics on some sub-classes of
MetaItemInner.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add get_locus method.
* ast/rust-expr.h: Likewise.
* ast/rust-macro.h: Likewise.

Signed-off-by: Xiao Ma 
---
 gcc/rust/ast/rust-ast.h   |  2 ++
 gcc/rust/ast/rust-expr.h  |  8 
 gcc/rust/ast/rust-macro.h | 12 
 3 files changed, 22 insertions(+)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 5f18233eb0f..d30e6d494f2 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -630,6 +630,8 @@ public:
 
   virtual ~MetaItemInner ();
 
+  virtual Location get_locus () const = 0;
+
   virtual std::string as_string () const = 0;
 
   virtual void accept_vis (ASTVisitor &vis) = 0;
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index c58fae5e564..34bc6993ab6 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -150,6 +150,8 @@ public:
 
   std::string as_string () const override { return lit_expr.as_string (); }
 
+  Location get_locus () const override { return lit_expr.get_locus (); }
+
   void accept_vis (ASTVisitor &vis) override;
 
   bool check_cfg_predicate (const Session &session) const override;
@@ -178,6 +180,12 @@ public:
 return path.as_string () + " = " + lit.as_string ();
   }
 
+  // There are two Locations in MetaItemPathLit (path and lit_expr),
+  //  we have no idea use which of them, just simply return UNKNOWN_LOCATION
+  //  now.
+  // Maybe we will figure out when we really need the location in the future.
+  Location get_locus () const override { return Location (UNKNOWN_LOCATION); }
+
   void accept_vis (ASTVisitor &vis) override;
 
   bool check_cfg_predicate (const Session &session) const override;
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index bff8c7ac6fb..4226c6919ff 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -725,6 +725,8 @@ public:
 return path;
   }
 
+  Location get_locus () const override { return path.get_locus (); }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -778,6 +780,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return path.get_locus (); }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -805,6 +809,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -847,6 +853,8 @@ public:
 return std::unique_ptr (clone_meta_item_inner_impl ());
   }
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -885,6 +893,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -919,6 +929,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 24/88] gccrs: Create and use CompilePatternLet visitor for compiling let statments

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternLet::visit): New 
function.
* backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise.
* backend/rust-compile-pattern.h (class CompilePatternLet): New visitor.

Signed-off-by: Owen Avery 
---
 gcc/rust/backend/rust-compile-pattern.cc | 58 
 gcc/rust/backend/rust-compile-pattern.h  | 87 
 gcc/rust/backend/rust-compile-stmt.cc| 31 +
 3 files changed, 148 insertions(+), 28 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-pattern.cc 
b/gcc/rust/backend/rust-compile-pattern.cc
index 9218b815dd8..e13d6caf7e6 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -341,5 +341,63 @@ CompilePatternBindings::visit (HIR::GroupedPattern 
&pattern)
   pattern.get_item ()->accept_vis (*this);
 }
 
+void
+CompilePatternLet::visit (HIR::IdentifierPattern &pattern)
+{
+  Bvariable *var = nullptr;
+  rust_assert (
+ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var));
+
+  auto fnctx = ctx->peek_fn ();
+  if (ty->is_unit ())
+{
+  ctx->add_statement (init_expr);
+
+  tree stmt_type = TyTyResolveCompile::compile (ctx, ty);
+
+  auto unit_type_init_expr
+   = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1,
+  rval_locus);
+  auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var,
+   unit_type_init_expr);
+  ctx->add_statement (s);
+}
+  else
+{
+  auto s
+   = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr);
+  ctx->add_statement (s);
+}
+}
+
+void
+CompilePatternLet::visit (HIR::WildcardPattern &pattern)
+{
+  Bvariable *var = nullptr;
+  rust_assert (
+ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var));
+
+  auto fnctx = ctx->peek_fn ();
+  if (ty->is_unit ())
+{
+  ctx->add_statement (init_expr);
+
+  tree stmt_type = TyTyResolveCompile::compile (ctx, ty);
+
+  auto unit_type_init_expr
+   = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1,
+  rval_locus);
+  auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var,
+   unit_type_init_expr);
+  ctx->add_statement (s);
+}
+  else
+{
+  auto s
+   = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr);
+  ctx->add_statement (s);
+}
+}
+
 } // namespace Compile
 } // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-pattern.h 
b/gcc/rust/backend/rust-compile-pattern.h
index 43334affca7..317a3451161 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -91,5 +91,92 @@ protected:
   tree match_scrutinee_expr;
 };
 
+class CompilePatternLet : public HIRCompileBase, public HIR::HIRPatternVisitor
+{
+public:
+  static void Compile (HIR::Pattern *pattern, tree init_expr,
+  TyTy::BaseType *ty, Location rval_locus, Context *ctx)
+  {
+CompilePatternLet compiler (ctx, init_expr, ty, rval_locus);
+pattern->accept_vis (compiler);
+  }
+
+  void visit (HIR::IdentifierPattern &) override;
+  void visit (HIR::WildcardPattern &) override;
+
+  // check for unimplemented Pattern HIR nodes.
+  void visit (HIR::GroupedPattern &pattern) override
+  {
+rust_sorry_at (pattern.get_locus (),
+  "grouped pattern let statements not supported");
+  }
+
+  void visit (HIR::LiteralPattern &pattern) override
+  {
+rust_sorry_at (pattern.get_locus (),
+  "literal pattern let statements not supported");
+  }
+
+  void visit (HIR::PathInExpression &pattern) override
+  {
+rust_sorry_at (pattern.get_locus (),
+  "path-in-expression pattern let statements not supported");
+  }
+
+  void visit (HIR::QualifiedPathInExpression &pattern) override
+  {
+rust_sorry_at (
+  pattern.get_locus (),
+  "qualified-path-in-expression pattern let statements not supported");
+  }
+
+  void visit (HIR::RangePattern &pattern) override
+  {
+rust_sorry_at (pattern.get_locus (),
+  "range pattern let statements not supported");
+  }
+
+  void visit (HIR::ReferencePattern &pattern) override
+  {
+rust_sorry_at (pattern.get_locus (),
+  "reference pattern let statements not supported");
+  }
+
+  void visit (HIR::SlicePattern &pattern) override
+  {
+rust_sorry_at (pattern.get_locus (),
+  "slice pattern let statements not supported");
+  }
+
+  void visit (HIR::StructPattern &pattern) override
+  {
+rust_sorry_at (pattern.get_locus (),
+  "struct pattern let statements not supported");
+  }
+
+  void visit (HIR::TuplePattern &patter

[committed 12/88] gccrs: testsuite: Handle Windows carriage returns properly

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

In dg-output, check for \r* carriage returns to make sure execution
tests pass on windows platforms

gcc/testsuite/ChangeLog:

* rust/execute/torture/builtin_macro_cfg.rs: Handle carriage returns
properly.
* rust/execute/torture/builtin_macro_concat.rs: Likewise.
* rust/execute/torture/builtin_macro_env.rs: Likewise.
* rust/execute/torture/builtin_macro_include_bytes.rs: Likewise.
* rust/execute/torture/builtin_macro_include_str.rs: Likewise.
* rust/execute/torture/builtin_macro_line.rs: Likewise.
* rust/execute/torture/builtin_macros1.rs: Likewise.
* rust/execute/torture/builtin_macros3.rs: Likewise.
* rust/execute/torture/cfg1.rs: Likewise.
* rust/execute/torture/cfg2.rs: Likewise.
* rust/execute/torture/cfg3.rs: Likewise.
* rust/execute/torture/cfg4.rs: Likewise.
* rust/execute/torture/coercion1.rs: Likewise.
* rust/execute/torture/coercion2.rs: Likewise.
* rust/execute/torture/extern_mod4.rs: Likewise.
* rust/execute/torture/helloworld1.rs: Likewise.
* rust/execute/torture/helloworld2.rs: Likewise.
* rust/execute/torture/issue-1198.rs: Likewise.
* rust/execute/torture/issue-1231.rs: Likewise.
* rust/execute/torture/issue-1232.rs: Likewise.
* rust/execute/torture/issue-1249.rs: Likewise.
* rust/execute/torture/issue-1436.rs: Likewise.
* rust/execute/torture/issue-1496.rs: Likewise.
* rust/execute/torture/issue-647.rs: Likewise.
* rust/execute/torture/issue-845.rs: Likewise.
* rust/execute/torture/issue-851.rs: Likewise.
* rust/execute/torture/issue-858.rs: Likewise.
* rust/execute/torture/issue-976.rs: Likewise.
* rust/execute/torture/macros10.rs: Likewise.
* rust/execute/torture/macros11.rs: Likewise.
* rust/execute/torture/macros12.rs: Likewise.
* rust/execute/torture/macros13.rs: Likewise.
* rust/execute/torture/macros14.rs: Likewise.
* rust/execute/torture/macros2.rs: Likewise.
* rust/execute/torture/macros22.rs: Likewise.
* rust/execute/torture/macros29.rs: Likewise.
* rust/execute/torture/macros3.rs: Likewise.
* rust/execute/torture/macros30.rs: Likewise.
* rust/execute/torture/macros31.rs: Likewise.
* rust/execute/torture/macros7.rs: Likewise.
* rust/execute/torture/macros8.rs: Likewise.
* rust/execute/torture/macros9.rs: Likewise.
* rust/execute/torture/match1.rs: Likewise.
* rust/execute/torture/match2.rs: Likewise.
* rust/execute/torture/match3.rs: Likewise.
* rust/execute/torture/match_bool1.rs: Likewise.
* rust/execute/torture/match_byte1.rs: Likewise.
* rust/execute/torture/match_char1.rs: Likewise.
* rust/execute/torture/match_int1.rs: Likewise.
* rust/execute/torture/match_loop1.rs: Likewise.
* rust/execute/torture/match_range1.rs: Likewise.
* rust/execute/torture/match_range2.rs: Likewise.
* rust/execute/torture/match_tuple1.rs: Likewise.
* rust/execute/torture/method1.rs: Likewise.
* rust/execute/torture/method2.rs: Likewise.
* rust/execute/torture/method3.rs: Likewise.
* rust/execute/torture/method4.rs: Likewise.
* rust/execute/torture/operator_overload_1.rs: Likewise.
* rust/execute/torture/operator_overload_10.rs: Likewise.
* rust/execute/torture/operator_overload_11.rs: Likewise.
* rust/execute/torture/operator_overload_12.rs: Likewise.
* rust/execute/torture/operator_overload_2.rs: Likewise.
* rust/execute/torture/operator_overload_4.rs: Likewise.
* rust/execute/torture/operator_overload_5.rs: Likewise.
* rust/execute/torture/operator_overload_6.rs: Likewise.
* rust/execute/torture/operator_overload_7.rs: Likewise.
* rust/execute/torture/operator_overload_8.rs: Likewise.
* rust/execute/torture/operator_overload_9.rs: Likewise.
* rust/execute/torture/str-layout1.rs: Likewise.
* rust/execute/torture/str-zero.rs: Likewise.
* rust/execute/torture/trait1.rs: Likewise.
* rust/execute/torture/trait10.rs: Likewise.
* rust/execute/torture/trait11.rs: Likewise.
* rust/execute/torture/trait12.rs: Likewise.
* rust/execute/torture/trait13.rs: Likewise.
* rust/execute/torture/trait2.rs: Likewise.
* rust/execute/torture/trait3.rs: Likewise.
* rust/execute/torture/trait4.rs: Likewise.
* rust/execute/torture/trait5.rs: Likewise.
* rust/execute/torture/trait6.rs: Likewise.
* rust/execute/torture/trait7.rs: Likewise.
* rust/execute/torture/trait8.rs: Likewise.
* rust/execute/torture/trait9.rs: Likewise.
* rust/execute/torture/closure2.rs: Likewise.
* rust/execute/torture/closure3.rs: Likewise.
   

[committed 33/88] gccrs: Add support for feature check.

2023-04-05 Thread arthur . cohen
From: mxlol233 

This commit implements a very basic feature checking module.

gcc/rust/ChangeLog:

* Make-lang.in: Add object files: `rust-feature.o` and 
`rust-feature-gate.o`
* checks/errors/rust-feature-gate.cc: New file.
* checks/errors/rust-feature-gate.h: New file.
* checks/errors/rust-feature.cc: New file.
* checks/errors/rust-feature.h: New file.
* rust-session-manager.cc: Add FeatureGate check.

gcc/testsuite/ChangeLog:

* rust/compile/feature.rs: New test.

Signed-off-by: Xiao Ma 
---
 gcc/rust/Make-lang.in   |   2 +
 gcc/rust/checks/errors/rust-feature-gate.cc |  63 +++
 gcc/rust/checks/errors/rust-feature-gate.h  | 191 
 gcc/rust/checks/errors/rust-feature.cc  |  66 +++
 gcc/rust/checks/errors/rust-feature.h   |  76 
 gcc/rust/rust-session-manager.cc|   4 +
 gcc/testsuite/rust/compile/feature.rs   |   4 +
 7 files changed, 406 insertions(+)
 create mode 100644 gcc/rust/checks/errors/rust-feature-gate.cc
 create mode 100644 gcc/rust/checks/errors/rust-feature-gate.h
 create mode 100644 gcc/rust/checks/errors/rust-feature.cc
 create mode 100644 gcc/rust/checks/errors/rust-feature.h
 create mode 100644 gcc/testsuite/rust/compile/feature.rs

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 87f3ba66eba..a0c5757592e 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -161,6 +161,8 @@ GRS_OBJS = \
 rust/rust-import-archive.o \
 rust/rust-extern-crate.o \
 rust/rust-builtins.o \
+rust/rust-feature.o \
+rust/rust-feature-gate.o \
 $(END)
 # removed object files from here
 
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
new file mode 100644
index 000..cd26f8a17f5
--- /dev/null
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -0,0 +1,63 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#include "rust-feature-gate.h"
+#include "rust-feature.h"
+
+namespace Rust {
+
+void
+FeatureGate::check (AST::Crate &crate)
+{
+  std::vector valid_features;
+  for (const auto &attr : crate.inner_attrs)
+{
+  if (attr.get_path ().as_string () == "feature")
+   {
+ const auto &attr_input = attr.get_attr_input ();
+ auto type = attr_input.get_attr_input_type ();
+ if (type == AST::AttrInput::AttrInputType::TOKEN_TREE)
+   {
+ const auto &option = static_cast (
+   attr.get_attr_input ());
+ std::unique_ptr meta_item (
+   option.parse_to_meta_item ());
+ for (const auto &item : meta_item->get_items ())
+   {
+ const auto &name = item->as_string ();
+ auto tname = Feature::as_name (name);
+ if (!tname.is_none ())
+   valid_features.push_back (Feature::create (tname.get ()));
+ else
+   rust_error_at (item->get_locus (), "unknown feature '%s'",
+  name.c_str ());
+   }
+   }
+   }
+}
+  valid_features.shrink_to_fit ();
+
+  // TODO (mxlol233): add the real feature gate stuff.
+  auto &items = crate.items;
+  for (auto it = items.begin (); it != items.end (); it++)
+{
+  auto &item = *it;
+  item->accept_vis (*this);
+}
+}
+} // namespace Rust
\ No newline at end of file
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
new file mode 100644
index 000..080c15ccd23
--- /dev/null
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -0,0 +1,191 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General 

[committed 41/88] gccrs: Refactor PathProbe into cc file

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): 
refactor
(PathProbeType::Probe): likewise
(PathProbeType::visit): likewise
(PathProbeType::process_enum_item_for_candiates): likewise
(PathProbeType::process_impl_items_for_candidates): likewise
(PathProbeType::is_reciever_generic): likewise
(PathProbeImplTrait::PathProbeImplTrait): likewise
(PathProbeImplTrait::Probe): likewise
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise
* typecheck/rust-hir-trait-resolve.cc
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
---
 gcc/rust/typecheck/rust-hir-path-probe.cc| 344 +++
 gcc/rust/typecheck/rust-hir-path-probe.h | 302 +---
 gcc/rust/typecheck/rust-hir-trait-resolve.cc |  22 --
 3 files changed, 360 insertions(+), 308 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc 
b/gcc/rust/typecheck/rust-hir-path-probe.cc
index cb3270d3623..06d8920d2eb 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -18,10 +18,168 @@
 
 #include "rust-hir-path-probe.h"
 #include "rust-hir-type-check-item.h"
+#include "rust-hir-trait-resolve.h"
 
 namespace Rust {
 namespace Resolver {
 
+// PathProbeType
+
+PathProbeType::PathProbeType (const TyTy::BaseType *receiver,
+ const HIR::PathIdentSegment &query,
+ DefId specific_trait_id)
+  : TypeCheckBase (), receiver (receiver), search (query),
+current_impl (nullptr), specific_trait_id (specific_trait_id)
+{}
+
+std::set
+PathProbeType::Probe (const TyTy::BaseType *receiver,
+ const HIR::PathIdentSegment &segment_name,
+ bool probe_impls, bool probe_bounds,
+ bool ignore_mandatory_trait_items,
+ DefId specific_trait_id)
+{
+  PathProbeType probe (receiver, segment_name, specific_trait_id);
+  if (probe_impls)
+{
+  if (receiver->get_kind () == TyTy::TypeKind::ADT)
+   {
+ const TyTy::ADTType *adt
+   = static_cast (receiver);
+ if (adt->is_enum ())
+   probe.process_enum_item_for_candiates (adt);
+   }
+
+  probe.process_impl_items_for_candidates ();
+}
+
+  if (!probe_bounds)
+return probe.candidates;
+
+  if (!probe.is_reciever_generic ())
+{
+  std::vector> probed_bounds
+   = TypeBoundsProbe::Probe (receiver);
+  for (auto &candidate : probed_bounds)
+   {
+ const TraitReference *trait_ref = candidate.first;
+ if (specific_trait_id != UNKNOWN_DEFID)
+   {
+ if (trait_ref->get_mappings ().get_defid () != specific_trait_id)
+   continue;
+   }
+
+ HIR::ImplBlock *impl = candidate.second;
+ probe.process_associated_trait_for_candidates (
+   trait_ref, impl, ignore_mandatory_trait_items);
+   }
+}
+
+  for (const TyTy::TypeBoundPredicate &predicate :
+   receiver->get_specified_bounds ())
+{
+  const TraitReference *trait_ref = predicate.get ();
+  if (specific_trait_id != UNKNOWN_DEFID)
+   {
+ if (trait_ref->get_mappings ().get_defid () != specific_trait_id)
+   continue;
+   }
+
+  probe.process_predicate_for_candidates (predicate,
+ ignore_mandatory_trait_items);
+}
+
+  return probe.candidates;
+}
+
+void
+PathProbeType::visit (HIR::TypeAlias &alias)
+{
+  Identifier name = alias.get_new_type_name ();
+  if (search.as_string ().compare (name) == 0)
+{
+  HirId tyid = alias.get_mappings ().get_hirid ();
+  TyTy::BaseType *ty = nullptr;
+  bool ok = query_type (tyid, &ty);
+  rust_assert (ok);
+
+  PathProbeCandidate::ImplItemCandidate impl_item_candidate{&alias,
+   current_impl};
+  PathProbeCandidate candidate{
+   PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS, ty,
+   alias.get_locus (), impl_item_candidate};
+  candidates.insert (std::move (candidate));
+}
+}
+
+void
+PathProbeType::visit (HIR::ConstantItem &constant)
+{
+  Identifier name = constant.get_identifier ();
+  if (search.as_string ().compare (name) == 0)
+{
+  HirId tyid = constant.get_mappings ().get_hirid ();
+  TyTy::BaseType *ty = nullptr;
+  bool ok = query_type (tyid, &ty);
+  rust_assert (ok);
+
+  PathProbeCandidate::ImplItemCandidate impl_item_candidate{&constant,
+   current_impl};
+  PathProbeCandidate candidate{
+   PathProbeCandidate::CandidateType::IMPL_CONST, ty,
+   constant.get_locus (), impl_item_can

[committed 46/88] gccrs: Refactor handle_substitutions to take a reference

2023-04-05 Thread arthur . cohen
From: Philip Herron 

This patch changes the recusive substitution code to take a reference
instead of a copy. This is important as the callback field is going to be
made non-copyable in a future patch and this pipeline is for recursive
substitutions so its ok to reuse the same mappings here.

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc: refactor to take a reference
* typecheck/rust-tyty-subst.cc: likewise
(SubstitutionRef::get_substitution_arguments): likewise
(SubstitutionRef::infer_substitions): likewise
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise
(TupleType::handle_substitions): likewise
(FnType::handle_substitions): likewise
(ClosureType::handle_substitions): likewise
(ArrayType::handle_substitions): likewise
(SliceType::handle_substitions): likewise
(ReferenceType::handle_substitions): likewise
(PointerType::handle_substitions): likewise
(ParamType::handle_substitions): likewise
(ProjectionType::handle_substitions): likewise
* typecheck/rust-tyty.h: likewise
---
 gcc/rust/typecheck/rust-tyty-bounds.cc |  2 +-
 gcc/rust/typecheck/rust-tyty-subst.cc  | 10 --
 gcc/rust/typecheck/rust-tyty-subst.h   |  5 +++--
 gcc/rust/typecheck/rust-tyty.cc| 21 +++--
 gcc/rust/typecheck/rust-tyty.h | 22 +++---
 5 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc 
b/gcc/rust/typecheck/rust-tyty-bounds.cc
index e7eb9a760f5..b14e0c68e5a 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -444,7 +444,7 @@ TypeBoundPredicate::is_error () const
 
 BaseType *
 TypeBoundPredicate::handle_substitions (
-  SubstitutionArgumentMappings subst_mappings)
+  SubstitutionArgumentMappings &subst_mappings)
 {
   for (auto &sub : get_substs ())
 {
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index aceed29ff03..a5d738744fc 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -488,7 +488,13 @@ SubstitutionRef::was_substituted () const
   return !needs_substitution ();
 }
 
-SubstitutionArgumentMappings
+SubstitutionArgumentMappings &
+SubstitutionRef::get_substitution_arguments ()
+{
+  return used_arguments;
+}
+
+const SubstitutionArgumentMappings &
 SubstitutionRef::get_substitution_arguments () const
 {
   return used_arguments;
@@ -697,7 +703,7 @@ SubstitutionRef::infer_substitions (Location locus)
   SubstitutionArgumentMappings infer_arguments (std::move (args),
{} /* binding_arguments */,
locus);
-  return handle_substitions (std::move (infer_arguments));
+  return handle_substitions (infer_arguments);
 }
 
 SubstitutionArgumentMappings
diff --git a/gcc/rust/typecheck/rust-tyty-subst.h 
b/gcc/rust/typecheck/rust-tyty-subst.h
index 4d09a3013e7..039eb36589e 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.h
+++ b/gcc/rust/typecheck/rust-tyty-subst.h
@@ -199,7 +199,8 @@ public:
 
   bool was_substituted () const;
 
-  SubstitutionArgumentMappings get_substitution_arguments () const;
+  SubstitutionArgumentMappings &get_substitution_arguments ();
+  const SubstitutionArgumentMappings &get_substitution_arguments () const;
 
   // this is the count of type params that are not substituted fuly
   size_t num_required_substitutions () const;
@@ -301,7 +302,7 @@ public:
   bool monomorphize ();
 
   // TODO comment
-  virtual BaseType *handle_substitions (SubstitutionArgumentMappings mappings)
+  virtual BaseType *handle_substitions (SubstitutionArgumentMappings &mappings)
 = 0;
 
   SubstitutionArgumentMappings get_used_arguments () const;
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 4c324c66c16..a3271eb0d1a 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -1148,7 +1148,7 @@ handle_substitions (SubstitutionArgumentMappings 
&subst_mappings,
 }
 
 ADTType *
-ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
+ADTType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
 {
   ADTType *adt = static_cast (clone ());
   adt->set_ty_ref (mappings->get_next_hir_id ());
@@ -1333,7 +1333,7 @@ TupleType::monomorphized_clone () const
 }
 
 TupleType *
-TupleType::handle_substitions (SubstitutionArgumentMappings mappings)
+TupleType::handle_substitions (SubstitutionArgumentMappings &mappings)
 {
   auto mappings_table = Analysis::Mappings::get ();
 
@@ -1474,7 +1474,7 @@ FnType::monomorphized_clone () const
 }
 
 FnType *
-FnType::handle_substitions (SubstitutionArgumentMappings subst_mappings)
+FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
 {

[committed 51/88] gccrs: Fix nullptr dereference

2023-04-05 Thread arthur . cohen
From: Philip Herron 

When we check if this is concrete the guard checks to ensure the argument
is non null but the check here is wrongly returning early when the check
is non null meaning when it is null and therefore not concrete it will
end up doing a null dereference.

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc (SubstitutionArg::is_conrete): fix check
---
 gcc/rust/typecheck/rust-tyty-subst.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index 7f5bb22687d..996bbf2d885 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -213,8 +213,8 @@ SubstitutionArg::is_error () const
 bool
 SubstitutionArg::is_conrete () const
 {
-  if (argument != nullptr)
-return true;
+  if (argument == nullptr)
+return false;
 
   if (argument->get_kind () == TyTy::TypeKind::PARAM)
 return false;
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 34/88] gccrs: Removed comment copy-pasted from gcc/tree.def

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Removed 
copy-pasted comment.

Signed-off-by: Owen Avery 
---
 gcc/rust/backend/rust-compile-expr.cc | 24 
 1 file changed, 24 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index 436fc924a13..c26f6f440ec 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1341,30 +1341,6 @@ CompileExpr::visit (HIR::MatchExpr &expr)
   // SWITCH_ALL_CASES_P is true if the switch includes a default label or the
   // case label ranges cover all possible values of the condition expression
 
-  /* Switch expression.
-
- TREE_TYPE is the original type of the condition, before any
- language required type conversions.  It may be NULL, in which case
- the original type and final types are assumed to be the same.
-
- Operand 0 is the expression used to perform the branch,
- Operand 1 is the body of the switch, which probably contains
-   CASE_LABEL_EXPRs.  It may also be NULL, in which case operand 2
-   must not be NULL.  */
-  // DEFTREECODE (SWITCH_EXPR, "switch_expr", tcc_statement, 2)
-
-  /* Used to represent a case label.
-
- Operand 0 is CASE_LOW.  It may be NULL_TREE, in which case the label
-   is a 'default' label.
- Operand 1 is CASE_HIGH.  If it is NULL_TREE, the label is a simple
-   (one-value) case label.  If it is non-NULL_TREE, the case is a range.
- Operand 2 is CASE_LABEL, which has the corresponding LABEL_DECL.
- Operand 3 is CASE_CHAIN.  This operand is only used in tree-cfg.cc to
-   speed up the lookup of case labels which use a particular edge in
-   the control flow graph.  */
-  // DEFTREECODE (CASE_LABEL_EXPR, "case_label_expr", tcc_statement, 4)
-
   TyTy::TypeKind scrutinee_kind = check_match_scrutinee (expr, ctx);
   if (scrutinee_kind == TyTy::TypeKind::ERROR)
 {
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 29/88] gccrs: Optimize HIR::ReferencePattern

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(class ReferencePattern): Remove has_two_amps field.
* hir/tree/rust-hir-full-test.cc
(ReferencePattern::as_string): Remove usage of 
ReferencePattern::has_two_amps.

Signed-off-by: Owen Avery 
---
 gcc/rust/hir/tree/rust-hir-full-test.cc |  5 -
 gcc/rust/hir/tree/rust-hir-pattern.h| 13 +
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc 
b/gcc/rust/hir/tree/rust-hir-full-test.cc
index b6646d61b28..0ddb8418e95 100644
--- a/gcc/rust/hir/tree/rust-hir-full-test.cc
+++ b/gcc/rust/hir/tree/rust-hir-full-test.cc
@@ -2583,11 +2583,6 @@ ReferencePattern::as_string () const
 {
   std::string str ("&");
 
-  if (has_two_amps)
-{
-  str += "&";
-}
-
   if (is_mut ())
 {
   str += "mut ";
diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h 
b/gcc/rust/hir/tree/rust-hir-pattern.h
index 5243d7898c0..83b041d2770 100644
--- a/gcc/rust/hir/tree/rust-hir-pattern.h
+++ b/gcc/rust/hir/tree/rust-hir-pattern.h
@@ -424,7 +424,6 @@ protected:
 // HIR node for pattern based on dereferencing the pointers given
 class ReferencePattern : public Pattern
 {
-  bool has_two_amps;
   Mutability mut;
   std::unique_ptr pattern;
   Location locus;
@@ -435,16 +434,15 @@ public:
 
   ReferencePattern (Analysis::NodeMapping mappings,
std::unique_ptr pattern, Mutability reference_mut,
-   bool ref_has_two_amps, Location locus)
-: has_two_amps (ref_has_two_amps), mut (reference_mut),
-  pattern (std::move (pattern)), locus (locus), mappings (mappings)
+   Location locus)
+: mut (reference_mut), pattern (std::move (pattern)), locus (locus),
+  mappings (mappings)
   {}
 
   // Copy constructor requires clone
   ReferencePattern (ReferencePattern const &other)
-: has_two_amps (other.has_two_amps), mut (other.mut),
-  pattern (other.pattern->clone_pattern ()), locus (other.locus),
-  mappings (other.mappings)
+: mut (other.mut), pattern (other.pattern->clone_pattern ()),
+  locus (other.locus), mappings (other.mappings)
   {}
 
   // Overload assignment operator to clone
@@ -452,7 +450,6 @@ public:
   {
 pattern = other.pattern->clone_pattern ();
 mut = other.mut;
-has_two_amps = other.has_two_amps;
 locus = other.locus;
 mappings = other.mappings;
 
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 25/88] gccrs: parser: Allow parsing multiple reference types

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

The parser now recursively tries to parse a reference type after seeing
a `&` or `&&` token.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_type): Handle double ampersan
properly
(Parser::parse_reference_type): Call into `parse_reference_type_inner`
and wrap double reference types in another `AST::ReferenceType` node
(Parser::parse_reference_type_inner): Add parsing implementation
which does not care about the leading token (& or  &&)
(Parser::parse_type_no_bounds): Handle double ampersand properly
* parse/rust-parse.h: Declare `parse_reference_type_inner`

gcc/testsuite/ChangeLog:

* rust/compile/multi_reference_type.rs: New test.
---
 gcc/rust/parse/rust-parse-impl.h  | 33 +++
 gcc/rust/parse/rust-parse.h   |  2 ++
 .../rust/compile/multi_reference_type.rs  | 12 +++
 3 files changed, 41 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/multi_reference_type.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index a0bc2e10d2f..23b033fb26e 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -9237,6 +9237,7 @@ Parser::parse_type (bool save_errors)
   // raw pointer type
   return parse_raw_pointer_type ();
 case AMP: // does this also include AMP_AMP?
+case LOGICAL_AND:
   // reference type
   return parse_reference_type ();
   case LIFETIME: {
@@ -9886,14 +9887,10 @@ Parser::parse_bare_function_type (
   std::move (return_type), best_try_locus));
 }
 
-// Parses a reference type (mutable or immutable, with given lifetime).
 template 
 std::unique_ptr
-Parser::parse_reference_type ()
+Parser::parse_reference_type_inner (Location locus)
 {
-  Location locus = lexer.peek_token ()->get_locus ();
-  skip_token (AMP);
-
   // parse optional lifetime
   AST::Lifetime lifetime = AST::Lifetime::error ();
   if (lexer.peek_token ()->get_id () == LIFETIME)
@@ -9932,6 +9929,29 @@ Parser::parse_reference_type ()
std::move (lifetime)));
 }
 
+// Parses a reference type (mutable or immutable, with given lifetime).
+template 
+std::unique_ptr
+Parser::parse_reference_type ()
+{
+  auto t = lexer.peek_token ();
+  auto locus = t->get_locus ();
+
+  switch (t->get_id ())
+{
+case AMP:
+  skip_token (AMP);
+  return parse_reference_type_inner (locus);
+case LOGICAL_AND:
+  skip_token (LOGICAL_AND);
+  return std::unique_ptr (
+   new AST::ReferenceType (false, parse_reference_type_inner (locus),
+   locus));
+default:
+  gcc_unreachable ();
+}
+}
+
 // Parses a raw (unsafe) pointer type.
 template 
 std::unique_ptr
@@ -10079,7 +10099,8 @@ Parser::parse_type_no_bounds ()
 case ASTERISK:
   // raw pointer type
   return parse_raw_pointer_type ();
-case AMP: // does this also include AMP_AMP?
+case AMP: // does this also include AMP_AMP? Yes! Which is... LOGICAL_AND?
+case LOGICAL_AND:
   // reference type
   return parse_reference_type ();
 case LIFETIME:
diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 5c0fcc3f174..2f767bb2a53 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -604,6 +604,8 @@ private:
   std::unique_ptr parse_type_no_bounds ();
   std::unique_ptr parse_slice_or_array_type ();
   std::unique_ptr parse_raw_pointer_type ();
+  std::unique_ptr
+  parse_reference_type_inner (Location locus);
   std::unique_ptr parse_reference_type ();
   std::unique_ptr
   parse_bare_function_type (std::vector for_lifetimes);
diff --git a/gcc/testsuite/rust/compile/multi_reference_type.rs 
b/gcc/testsuite/rust/compile/multi_reference_type.rs
new file mode 100644
index 000..5ad7d84adbc
--- /dev/null
+++ b/gcc/testsuite/rust/compile/multi_reference_type.rs
@@ -0,0 +1,12 @@
+fn main() {
+let a = 15u8;
+let a: &u8 = &a;
+let a: &&u8 = &a;
+let a: &&&u8 = &a;
+let _: u8 = &a;
+
+let _: &&u8;
+let _: &mut &u8;
+let _: &&mut u8;
+let _: &mut &mut &u8;
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 43/88] gccrs: Refactor all code out of the rust-tyty.h header

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h: refactor
* typecheck/rust-tyctx.cc (TypeCheckContext::iterate): refactor
(TypeCheckContext::have_loop_context): likewise
(TypeCheckContext::push_new_loop_context): likewise
(TypeCheckContext::push_new_while_loop_context): likewise
(TypeCheckContext::peek_loop_context): likewise
(TypeCheckContext::pop_loop_context): likewise
(TypeCheckContext::swap_head_loop_context): likewise
(TypeCheckContext::insert_trait_reference): likewise
(TypeCheckContext::lookup_trait_reference): likewise
(TypeCheckContext::insert_receiver): likewise
(TypeCheckContext::lookup_receiver): likewise
(TypeCheckContext::insert_associated_type_mapping): likewise
(TypeCheckContext::clear_associated_type_mapping): likewise
(TypeCheckContext::lookup_associated_type_mapping): likewise
(TypeCheckContext::insert_variant_definition): likewise
(TypeCheckContext::lookup_variant_definition): likewise
(TypeCheckContext::insert_operator_overload): likewise
(TypeCheckContext::lookup_operator_overload): likewise
(TypeCheckContext::insert_unconstrained_check_marker): likewise
(TypeCheckContext::have_checked_for_unconstrained): likewise
(TypeCheckContext::insert_resolved_predicate): likewise
(TypeCheckContext::lookup_predicate): likewise
(TypeCheckContext::insert_query): likewise
(TypeCheckContext::query_completed): likewise
(TypeCheckContext::query_in_progress): likewise
(TypeCheckContext::insert_trait_query): likewise
(TypeCheckContext::trait_query_completed): likewise
(TypeCheckContext::trait_query_in_progress): likewise
(TypeCheckContextItem::Item::Item): likewise
(TypeCheckContextItem::TypeCheckContextItem): likewise
(TypeCheckContextItem::get_item): likewise
(TypeCheckContextItem::get_impl_item): likewise
(TypeCheckContextItem::get_trait_item): likewise
(TypeCheckContextItem::get_type): likewise
* typecheck/rust-tyty.cc (StructFieldType::StructFieldType): likewise
(StructFieldType::get_ref): likewise
(StructFieldType::get_name): likewise
(StructFieldType::get_field_type): likewise
(StructFieldType::set_field_type): likewise
(StructFieldType::is_concrete): likewise
(StructFieldType::debug): likewise
(StructFieldType::get_locus): likewise
(VariantDef::variant_type_string): likewise
(VariantDef::VariantDef): likewise
(VariantDef::operator=): likewise
(VariantDef::get_error_node): likewise
(VariantDef::is_error): likewise
(VariantDef::get_id): likewise
(VariantDef::get_defid): likewise
(VariantDef::get_variant_type): likewise
(VariantDef::is_data_variant): likewise
(VariantDef::is_dataless_variant): likewise
(VariantDef::get_identifier): likewise
(VariantDef::num_fields): likewise
(VariantDef::get_field_at_index): likewise
(VariantDef::get_fields): likewise
(VariantDef::lookup_field): likewise
(VariantDef::get_discriminant): likewise
(VariantDef::as_string): likewise
(VariantDef::is_equal): likewise
(VariantDef::clone): likewise
(VariantDef::monomorphized_clone): likewise
(VariantDef::get_ident): likewise
(TupleType::TupleType): likewise
(TupleType::get_unit_type): likewise
(TupleType::is_unit): likewise
(TupleType::num_fields): likewise
(TupleType::is_concrete): likewise
(TupleType::get_fields): likewise
(BoolType::BoolType): likewise
(BoolType::get_name): likewise
(BoolType::is_concrete): likewise
(IntType::IntType): likewise
(IntType::get_name): likewise
(IntType::get_int_kind): likewise
(IntType::is_concrete): likewise
(UintType::UintType): likewise
(UintType::get_name): likewise
(UintType::get_uint_kind): likewise
(UintType::is_concrete): likewise
(FloatType::FloatType): likewise
(FloatType::get_name): likewise
(FloatType::get_float_kind): likewise
(FloatType::is_concrete): likewise
(USizeType::USizeType): likewise
(USizeType::get_name): likewise
(USizeType::is_concrete): likewise
(ISizeType::ISizeType): likewise
(ISizeType::get_name): likewise
(ISizeType::is_concrete): likewise
(CharType::CharType): likewise
(CharType::is_concrete): likewise
(CharType::get_name): likewise
(ReferenceType::ReferenceType): likewise
(ReferenceType::is_concrete): likewise
(ReferenceType::mutability): likewise
(ReferenceType::is_mutable): likewise
(ReferenceType::is_dyn_object): likewi

[committed 49/88] gccrs: Remove monomorphization hack to setup possible associated types

2023-04-05 Thread arthur . cohen
From: Philip Herron 

During CallExpr argument type checking we may be calling a default
implementation of a trait function this will require any possible
associated types to be resolved and setup. This monomoprhization call does
this but it will premtivly do extra unification of types which will throw
off type checking later on. This fix is required for my work into type
bounds checking.

Fixes #1773

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: change interface to return self
* typecheck/rust-hir-trait-resolve.cc: likewise
* typecheck/rust-hir-type-check-path.cc 
(TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove 
monomorphization hack

gcc/testsuite/ChangeLog:

* rust/compile/issue-1773.rs: New test.
---
 gcc/rust/typecheck/rust-hir-trait-reference.h |  5 +--
 gcc/rust/typecheck/rust-hir-trait-resolve.cc  | 10 +++---
 .../typecheck/rust-hir-type-check-path.cc | 36 ++-
 gcc/rust/typecheck/rust-tyty-call.cc  |  1 -
 gcc/testsuite/rust/compile/issue-1773.rs  | 20 +++
 5 files changed, 56 insertions(+), 16 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-1773.rs

diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h 
b/gcc/rust/typecheck/rust-hir-trait-reference.h
index 0df35265959..9b4461b9f18 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -497,8 +497,9 @@ public:
 
   TyTy::BaseType *get_self () { return self; }
 
-  void setup_associated_types (const TyTy::BaseType *self,
-  const TyTy::TypeBoundPredicate &bound);
+  TyTy::BaseType *
+  setup_associated_types (const TyTy::BaseType *self,
+ const TyTy::TypeBoundPredicate &bound);
 
   void reset_associated_types ();
 
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index e2d0cf2d7a2..6e23093eceb 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -377,13 +377,10 @@ TraitItemReference::associated_type_reset () const
   placeholder->clear_associated_type ();
 }
 
-void
+TyTy::BaseType *
 AssociatedImplTrait::setup_associated_types (
   const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound)
 {
-  if (!bound.contains_associated_types ())
-return;
-
   // compute the constrained impl block generic arguments based on self and the
   // higher ranked trait bound
   TyTy::BaseType *receiver = self->clone ();
@@ -486,6 +483,7 @@ AssociatedImplTrait::setup_associated_types (
 TyTy::TyWithLocation (receiver), TyTy::TyWithLocation (impl_self_infer),
 impl_predicate.get_locus ());
   rust_assert (result->get_kind () != TyTy::TypeKind::ERROR);
+  TyTy::BaseType *self_result = result;
 
   // unify the bounds arguments
   std::vector hrtb_bound_arguments;
@@ -500,7 +498,7 @@ AssociatedImplTrait::setup_associated_types (
 }
 
   if (impl_trait_predicate_args.size () != hrtb_bound_arguments.size ())
-return;
+return self_result;
 
   for (size_t i = 0; i < impl_trait_predicate_args.size (); i++)
 {
@@ -554,6 +552,8 @@ AssociatedImplTrait::setup_associated_types (
 resolved_trait_item->associated_type_set (substituted);
   });
   iter.go ();
+
+  return self_result;
 }
 
 void
diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc 
b/gcc/rust/typecheck/rust-hir-type-check-path.cc
index 6f1fd416c19..9d9b2949944 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-path.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc
@@ -379,16 +379,36 @@ TypeCheckExpr::resolve_segments (NodeId 
root_resolved_node_id,
 
   if (associated_impl_block != nullptr)
{
- // get the type of the parent Self
- HirId impl_ty_id
-   = associated_impl_block->get_type ()->get_mappings ().get_hirid ();
+ // associated types
+ HirId impl_block_id
+   = associated_impl_block->get_mappings ().get_hirid ();
+
+ AssociatedImplTrait *associated = nullptr;
+ bool found_impl_trait
+   = context->lookup_associated_trait_impl (impl_block_id,
+&associated);
  TyTy::BaseType *impl_block_ty = nullptr;
- bool ok = query_type (impl_ty_id, &impl_block_ty);
- rust_assert (ok);
+ if (found_impl_trait)
+   {
+ TyTy::TypeBoundPredicate predicate (*associated->get_trait (),
+ seg.get_locus ());
+ impl_block_ty
+   = associated->setup_associated_types (prev_segment, predicate);
+   }
+ else
+   {
+ // get the type of the parent Self
+ HirId impl_ty_id = associated_impl_block->get_type ()
+  ->get_mappings

[committed 57/88] gccrs: rust-item: include rust-expr.h

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* ast/rust-item.h (class BlockExpr): Remove forward declaration of
class `BlockExpr`.
---
 gcc/rust/ast/rust-item.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 37ed2beabfc..51ed815c700 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -22,11 +22,11 @@
 #include "rust-ast.h"
 #include "rust-path.h"
 #include "rust-common.h"
+#include "rust-expr.h"
 
 namespace Rust {
 namespace AST {
 // forward decls
-class BlockExpr;
 class TypePath;
 
 // TODO: inline?
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 63/88] gccrs: cli: Update safety warning message

2023-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

The compiler's warning message about the safety flag did not match
cargo-gccrs environment variable name anymore.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Update the
environment variable name.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/rust-session-manager.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 0f460e2d2f4..a086f83a3d0 100644
--- a/gcc/rust/rust-session-manager.cc
+++ b/gcc/rust/rust-session-manager.cc
@@ -441,7 +441,7 @@ Session::compile_crate (const char *filename)
   "defining the following environment variable (any value will "
   "do)\n\nGCCRS_INCOMPLETE_AND_EXPERIMENTAL_COMPILER_DO_NOT_USE\n\nFor "
   "cargo-gccrs, this means passing\n\n"
-  "GCCRS_EXTRA_FLAGS=\"-frust-incomplete-and-experimental-compiler-do-not-"
+  "GCCRS_EXTRA_ARGS=\"-frust-incomplete-and-experimental-compiler-do-not-"
   "use\"\n\nas an environment variable.");
 
   RAIIFile file_wrap (filename);
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 52/88] gccrs: Add missing Sized, Copy and Clone lang item mappings

2023-04-05 Thread arthur . cohen
From: Philip Herron 

We need these lang items to be defined and later down the line the mappings
will be used to implement proper copy and clone logic.

Fixes #1786

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* util/rust-lang-item.h:

gcc/testsuite/ChangeLog:

* rust/compile/issue-1786.rs: New test.
---
 gcc/rust/util/rust-lang-item.h   | 24 
 gcc/testsuite/rust/compile/issue-1786.rs | 23 +++
 2 files changed, 47 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-1786.rs

diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 29c364bad61..c5ef6200fb4 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -80,6 +80,12 @@ public:
 FN_ONCE,
 FN_ONCE_OUTPUT,
 
+// markers
+COPY,
+CLONE,
+SIZED,
+
+// delimiter
 UNKNOWN,
   };
 
@@ -237,6 +243,18 @@ public:
   {
return ItemType::FN_ONCE_OUTPUT;
   }
+else if (item.compare ("copy") == 0)
+  {
+   return ItemType::COPY;
+  }
+else if (item.compare ("clone") == 0)
+  {
+   return ItemType::CLONE;
+  }
+else if (item.compare ("sized") == 0)
+  {
+   return ItemType::SIZED;
+  }
 
 return ItemType::UNKNOWN;
   }
@@ -321,6 +339,12 @@ public:
return "fn_once";
   case FN_ONCE_OUTPUT:
return "fn_once_output";
+  case COPY:
+   return "copy";
+  case CLONE:
+   return "clone";
+  case SIZED:
+   return "sized";
 
   case UNKNOWN:
return "";
diff --git a/gcc/testsuite/rust/compile/issue-1786.rs 
b/gcc/testsuite/rust/compile/issue-1786.rs
new file mode 100644
index 000..f73b63d0cb6
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1786.rs
@@ -0,0 +1,23 @@
+#[lang = "clone"]
+trait Clone {
+fn clone(&self) -> Self;
+
+fn clone_from(&mut self, source: &Self) {
+*self = source.clone()
+}
+}
+
+#[lang = "copy"]
+pub trait Copy: Clone {
+// Empty.
+}
+
+mod impls {
+use super::Clone;
+
+impl Clone for char {
+fn clone(&self) -> Self {
+*self
+}
+}
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 62/88] gccrs: typecheck: Refactor rust-hir-trait-reference.h

2023-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

Move function body to their own cc file instead of keeping them in the
header file.

gcc/rust/ChangeLog:

* Make-lang.in: Add `rust-hir-trait-reference.o`.
* typecheck/rust-hir-trait-reference.h: Remove multiple function body.
* typecheck/rust-hir-trait-reference.cc: Add multiple function body.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/Make-lang.in |   1 +
 .../typecheck/rust-hir-trait-reference.cc | 463 ++
 gcc/rust/typecheck/rust-hir-trait-reference.h | 343 ++---
 3 files changed, 510 insertions(+), 297 deletions(-)
 create mode 100644 gcc/rust/typecheck/rust-hir-trait-reference.cc

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index d9bc40945c3..09bbe450bd5 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -123,6 +123,7 @@ GRS_OBJS = \
 rust/rust-tyty-bounds.o \
 rust/rust-hir-type-check-util.o \
 rust/rust-hir-trait-resolve.o \
+rust/rust-hir-trait-reference.o \
 rust/rust-hir-type-check-item.o \
 rust/rust-hir-type-check-type.o \
 rust/rust-hir-type-check-struct.o \
diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.cc 
b/gcc/rust/typecheck/rust-hir-trait-reference.cc
new file mode 100644
index 000..651c55abc82
--- /dev/null
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.cc
@@ -0,0 +1,463 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// .
+
+#include "rust-hir-trait-reference.h"
+
+namespace Rust {
+namespace Resolver {
+
+std::string
+TraitItemReference::as_string () const
+{
+  return "(" + trait_item_type_as_string (type) + " " + identifier + " " + ")";
+}
+
+bool
+TraitItemReference::is_error () const
+{
+  return type == ERROR;
+}
+
+bool
+TraitItemReference::is_optional () const
+{
+  return optional_flag;
+};
+
+std::string
+TraitItemReference::get_identifier () const
+{
+  return identifier;
+}
+
+TraitItemReference::TraitItemType
+TraitItemReference::get_trait_item_type () const
+{
+  return type;
+}
+
+HIR::TraitItem *
+TraitItemReference::get_hir_trait_item () const
+{
+  return hir_trait_item;
+}
+
+Location
+TraitItemReference::get_locus () const
+{
+  return locus;
+}
+
+const Analysis::NodeMapping
+TraitItemReference::get_mappings () const
+{
+  return hir_trait_item->get_mappings ();
+}
+
+TyTy::BaseType *
+TraitItemReference::get_tyty () const
+{
+  rust_assert (hir_trait_item != nullptr);
+
+  switch (type)
+{
+case CONST:
+  return get_type_from_constant (
+   static_cast (*hir_trait_item));
+  break;
+
+case TYPE:
+  return get_type_from_typealias (
+   static_cast (*hir_trait_item));
+
+case FN:
+  return get_type_from_fn (
+   static_cast (*hir_trait_item));
+  break;
+
+default:
+  return get_error ();
+}
+
+  gcc_unreachable ();
+  return get_error ();
+}
+
+TyTy::ErrorType *
+TraitItemReference::get_error () const
+{
+  return new TyTy::ErrorType (get_mappings ().get_hirid ());
+}
+
+TraitReference::TraitReference (
+  const HIR::Trait *hir_trait_ref, std::vector item_refs,
+  std::vector super_traits,
+  std::vector substs)
+  : hir_trait_ref (hir_trait_ref), item_refs (item_refs),
+super_traits (super_traits)
+{
+  trait_substs.clear ();
+  trait_substs.reserve (substs.size ());
+  for (const auto &p : substs)
+trait_substs.push_back (p.clone ());
+}
+
+TraitReference::TraitReference (TraitReference const &other)
+  : hir_trait_ref (other.hir_trait_ref), item_refs (other.item_refs),
+super_traits (other.super_traits)
+{
+  trait_substs.clear ();
+  trait_substs.reserve (other.trait_substs.size ());
+  for (const auto &p : other.trait_substs)
+trait_substs.push_back (p.clone ());
+}
+
+TraitReference &
+TraitReference::operator= (TraitReference const &other)
+{
+  hir_trait_ref = other.hir_trait_ref;
+  item_refs = other.item_refs;
+  super_traits = other.super_traits;
+
+  trait_substs.clear ();
+  trait_substs.reserve (other.trait_substs.size ());
+  for (const auto &p : other.trait_substs)
+trait_substs.push_back (p.clone ());
+
+  return *this;
+}
+
+bool
+TraitReference::is_error () const
+{
+  return hir_trait_ref == nullptr;
+}
+
+Location
+TraitReference::get_locus () const
+{
+  return hir_trait_ref->get_locus ();
+}
+
+std::string

[committed 66/88] gccrs: Add variadic argument type checking

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc
(TypeCheckCallExpr::visit): Add variadic argument type checking.
(TypeCheckCallExpr::visit): Fix comment spelling ("varadic").

gcc/testsuite/ChangeLog:

* rust/execute/torture/overflow1.rs: Fix test.

Signed-off-by: Owen Avery 
---
 gcc/rust/typecheck/rust-tyty-call.cc  | 56 ++-
 .../rust/execute/torture/overflow1.rs |  2 +-
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-call.cc 
b/gcc/rust/typecheck/rust-tyty-call.cc
index 67e2866cbce..f0846ae25ec 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -122,7 +122,7 @@ TypeCheckCallExpr::visit (FnType &type)
  return;
}
 
-  // it might be a varadic function
+  // it might be a variadic function
   if (i < type.num_params ())
{
  auto fnparam = type.param_at (i);
@@ -143,6 +143,60 @@ TypeCheckCallExpr::visit (FnType &type)
  return;
}
}
+  else
+   {
+ switch (argument_expr_tyty->get_kind ())
+   {
+   case TyTy::TypeKind::ERROR:
+ return;
+ case TyTy::TypeKind::INT: {
+   auto &int_ty
+ = static_cast (*argument_expr_tyty);
+   if ((int_ty.get_int_kind () == TyTy::IntType::IntKind::I8)
+   || (int_ty.get_int_kind () == TyTy::IntType::IntKind::I16))
+ {
+   rust_error_at (arg_locus,
+  "expected % variadic argument");
+   return;
+ }
+   break;
+ }
+ case TyTy::TypeKind::UINT: {
+   auto &uint_ty
+ = static_cast (*argument_expr_tyty);
+   if ((uint_ty.get_uint_kind () == TyTy::UintType::UintKind::U8)
+   || (uint_ty.get_uint_kind ()
+   == TyTy::UintType::UintKind::U16))
+ {
+   rust_error_at (arg_locus,
+  "expected % variadic argument");
+   return;
+ }
+   break;
+ }
+ case TyTy::TypeKind::FLOAT: {
+   if (static_cast (*argument_expr_tyty)
+ .get_float_kind ()
+   == TyTy::FloatType::FloatKind::F32)
+ {
+   rust_error_at (arg_locus,
+  "expected % variadic argument");
+   return;
+ }
+   break;
+ }
+   case TyTy::TypeKind::BOOL:
+ rust_error_at (arg_locus, "expected % variadic argument");
+ return;
+   case TyTy::TypeKind::FNDEF:
+ rust_error_at (arg_locus,
+"unexpected function definition type as variadic "
+"argument - cast to function pointer");
+ return;
+   default:
+ break;
+   }
+   }
 
   i++;
 }
diff --git a/gcc/testsuite/rust/execute/torture/overflow1.rs 
b/gcc/testsuite/rust/execute/torture/overflow1.rs
index 57a0824ce0a..c4ccab1a133 100644
--- a/gcc/testsuite/rust/execute/torture/overflow1.rs
+++ b/gcc/testsuite/rust/execute/torture/overflow1.rs
@@ -16,5 +16,5 @@ fn main() {
 // { dg-final { scan-tree-dump ADD_OVERFLOW original } }
 let c = a + b;
 
-unsafe { printf("%d\n\0" as *const str as *const i8, c) }
+unsafe { printf("%d\n\0" as *const str as *const i8, c as i32) }
 }
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 65/88] gccrs: Add feature gate for "rust-intrinsic".

2023-04-05 Thread arthur . cohen
From: mxlol233 

This commit implemented a feature gate to check `intrinsics`.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc: Add implementation for
`void FeatureGate::visit (AST::ExternBlock &block)`. Add `valid_feature`
construction process in `FeatureGate::check`.
* checks/errors/rust-feature-gate.h: Add declaration for
`void FeatureGate::visit (AST::ExternBlock &block)`. Add private
variable `valid_feature`.
* checks/errors/rust-feature.h: Change `issue` to `m_issue`.

gcc/testsuite/ChangeLog:

* rust/compile/const-issue1440.rs: Add crate feature: `intrinsics`.
* rust/compile/feature_intrinsics.rs: New file.
* rust/compile/issue-1031.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1130.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1131.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1237.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1289.rs: Add crate feature: `intrinsics`.
* rust/compile/rust-const-blog-issue.rs: Add crate feature: 
`intrinsics`.
* rust/compile/torture/intrinsics-3.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-4.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-5.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-6.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-7.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1024.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1075.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1432.rs: Add crate feature: `intrinsics`.
* rust/compile/unsafe10.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/atomic_load.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/atomic_store.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/copy_nonoverlapping1.rs: Add crate feature:
`intrinsics`.
* rust/execute/torture/issue-1120.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/issue-1133.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/issue-1232.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/slice-magic.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/slice-magic2.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/str-layout1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/transmute1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/wrapping_op1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/wrapping_op2.rs: Add crate feature: `intrinsics`.

Signed-off-by: Xiao Ma 
---
 gcc/rust/checks/errors/rust-feature-gate.cc   | 61 ---
 gcc/rust/checks/errors/rust-feature-gate.h|  7 ++-
 gcc/rust/checks/errors/rust-feature.h |  5 +-
 gcc/testsuite/rust/compile/const-issue1440.rs |  1 +
 .../rust/compile/feature_intrinsics.rs|  7 +++
 gcc/testsuite/rust/compile/issue-1031.rs  |  2 +
 gcc/testsuite/rust/compile/issue-1130.rs  |  2 +
 gcc/testsuite/rust/compile/issue-1131.rs  |  2 +
 gcc/testsuite/rust/compile/issue-1237.rs  |  2 +
 gcc/testsuite/rust/compile/issue-1289.rs  |  2 +
 .../rust/compile/rust-const-blog-issue.rs |  2 +
 .../rust/compile/torture/intrinsics-3.rs  |  2 +
 .../rust/compile/torture/intrinsics-4.rs  |  2 +
 .../rust/compile/torture/intrinsics-5.rs  |  2 +
 .../rust/compile/torture/intrinsics-6.rs  |  2 +
 .../rust/compile/torture/intrinsics-7.rs  |  2 +
 .../rust/compile/torture/issue-1024.rs|  2 +
 .../rust/compile/torture/issue-1075.rs|  2 +
 .../rust/compile/torture/issue-1432.rs|  1 +
 gcc/testsuite/rust/compile/unsafe10.rs|  2 +
 .../rust/execute/torture/atomic_load.rs   |  2 +
 .../rust/execute/torture/atomic_store.rs  |  2 +
 .../execute/torture/copy_nonoverlapping1.rs   |  2 +
 .../rust/execute/torture/issue-1120.rs|  2 +
 .../rust/execute/torture/issue-1133.rs|  2 +
 .../rust/execute/torture/issue-1232.rs|  2 +
 .../rust/execute/torture/slice-magic.rs   |  2 +
 .../rust/execute/torture/slice-magic2.rs  |  2 +
 .../rust/execute/torture/str-layout1.rs   |  2 +
 .../rust/execute/torture/transmute1.rs|  1 +
 .../rust/execute/torture/wrapping_op1.rs  |  2 +
 .../rust/execute/torture/wrapping_op2.rs  |  2 +
 32 files changed, 122 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/feature_intrinsics.rs

diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index 31ce3679ee1..bd01b52c7ff 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -17,14 +17,15 @@
 /

[committed 53/88] gccrs: Fix higher ranked trait bounds computation of self

2023-04-05 Thread arthur . cohen
From: Philip Herron 

This updates the higher ranked trait bounds computation to handle ambigious
cases. When we have a slice for example:

  let slice = &a[1..3];

This works by reusing the Index operator overload from libcore, so when the
index range of 1..3 is computed, the type system needs to compute what the
types of index are; this works by integer inference variables
Range<> that need to be unified with the impl Index for
Range which computes the real type of usize for the index. This is
fine but what happens when we have the Copy and Clone traits bounds which
have implementations for all the primitive types i8, i16, i32, i64...
which is valid for any integer inference variable so the code prior to this
patch would have grabbed the first impl it would have found and used it
which is incorrect. When we have integer or float inference variables we
need to look for their respective defaults or emit an ambigious type bound
error.

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: add const infterface
* typecheck/rust-tyty-subst.cc 
(SubstitutionParamMapping::get_generic_param): make const
(SubstitutionRef::monomorphize): fix issue
* typecheck/rust-tyty-subst.h: constify interface
---
 gcc/rust/typecheck/rust-hir-trait-reference.h |   1 +
 gcc/rust/typecheck/rust-tyty-subst.cc | 107 --
 gcc/rust/typecheck/rust-tyty-subst.h  |   2 +-
 3 files changed, 102 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h 
b/gcc/rust/typecheck/rust-hir-trait-reference.h
index 9b4461b9f18..adb63b468d1 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -496,6 +496,7 @@ public:
   HIR::ImplBlock *get_impl_block () { return impl; }
 
   TyTy::BaseType *get_self () { return self; }
+  const TyTy::BaseType *get_self () const { return self; }
 
   TyTy::BaseType *
   setup_associated_types (const TyTy::BaseType *self,
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc 
b/gcc/rust/typecheck/rust-tyty-subst.cc
index 996bbf2d885..3dfe95873bc 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -65,7 +65,7 @@ SubstitutionParamMapping::get_param_ty () const
 }
 
 const HIR::TypeParam &
-SubstitutionParamMapping::get_generic_param ()
+SubstitutionParamMapping::get_generic_param () const
 {
   return generic;
 }
@@ -892,8 +892,7 @@ SubstitutionRef::monomorphize ()
  // setup any associated type mappings for the specified bonds and this
  // type
  auto candidates = Resolver::TypeBoundsProbe::Probe (binding);
-
- Resolver::AssociatedImplTrait *associated_impl_trait = nullptr;
+ std::vector associated_impl_traits;
  for (auto &probed_bound : candidates)
{
  const Resolver::TraitReference *bound_trait_ref
@@ -914,15 +913,109 @@ SubstitutionRef::monomorphize ()
= associated->get_self ()->can_eq (binding, false);
  if (found_trait && found_self)
{
- associated_impl_trait = associated;
- break;
+ associated_impl_traits.push_back (associated);
}
}
}
 
- if (associated_impl_trait != nullptr)
+ if (!associated_impl_traits.empty ())
{
- associated_impl_trait->setup_associated_types (binding, bound);
+ // This code is important when you look at slices for example when
+ // you have a slice such as:
+ //
+ // let slice = &array[1..3]
+ //
+ // the higher ranked bounds will end up having an Index trait
+ // implementation for Range so we need this code to resolve
+ // that we have an integer inference variable that needs to become
+ // a usize
+ //
+ // The other complicated issue is that we might have an intrinsic
+ // which requires the :Clone or Copy bound but the libcore adds
+ // implementations for all the integral types so when there are
+ // multiple candidates we need to resolve to the default
+ // implementation for that type otherwise its an error for
+ // ambiguous type bounds
+
+ if (associated_impl_traits.size () == 1)
+   {
+ Resolver::AssociatedImplTrait *associate_impl_trait
+   = associated_impl_traits.at (0);
+ associate_impl_trait->setup_associated_types (binding, bound);
+   }
+ else
+   {
+ // if we have a non-general inference variable we need to be
+ // careful about the selection here
+ bool is_infer_var
+   = binding->get_kind () == TyTy::TypeKin

[committed 68/88] gccrs: Simplify WildcardPattern let statement handling

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Simplify WildcardPattern compilation for 
let statements.
* backend/rust-compile-var-decl.h:
(CompileVarDecl::visit): Remove variable declaration for 
WildcardPattern.
* resolve/rust-ast-resolve-pattern.h:
(PatternDeclaration::visit): Remove name resolution for WildcardPattern.

Signed-off-by: Owen Avery 
---
 gcc/rust/backend/rust-compile-pattern.cc| 28 +
 gcc/rust/backend/rust-compile-var-decl.h| 16 +---
 gcc/rust/resolve/rust-ast-resolve-pattern.h |  7 --
 3 files changed, 7 insertions(+), 44 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-pattern.cc 
b/gcc/rust/backend/rust-compile-pattern.cc
index cb4b082f9c8..d98f7beb0e8 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -361,30 +361,14 @@ CompilePatternLet::visit (HIR::IdentifierPattern &pattern)
 void
 CompilePatternLet::visit (HIR::WildcardPattern &pattern)
 {
-  Bvariable *var = nullptr;
-  rust_assert (
-ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var));
-
-  auto fnctx = ctx->peek_fn ();
-  if (ty->is_unit ())
-{
-  ctx->add_statement (init_expr);
+  tree init_stmt = NULL;
+  tree stmt_type = TyTyResolveCompile::compile (ctx, ty);
 
-  tree stmt_type = TyTyResolveCompile::compile (ctx, ty);
+  ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
+  stmt_type, init_expr, false,
+  pattern.get_locus (), &init_stmt);
 
-  auto unit_type_init_expr
-   = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1,
-  rval_locus);
-  auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var,
-   unit_type_init_expr);
-  ctx->add_statement (s);
-}
-  else
-{
-  auto s
-   = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr);
-  ctx->add_statement (s);
-}
+  ctx->add_statement (init_stmt);
 }
 
 void
diff --git a/gcc/rust/backend/rust-compile-var-decl.h 
b/gcc/rust/backend/rust-compile-var-decl.h
index 9e07999f273..13b429d41e1 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -53,21 +53,6 @@ public:
 locals.push_back (var);
   }
 
-  void visit (HIR::WildcardPattern &pattern) override
-  {
-translated_type = ctx->get_backend ()->immutable_type (translated_type);
-
-Bvariable *var
-  = ctx->get_backend ()->local_variable (fndecl, "_", translated_type,
-NULL /*decl_var*/,
-pattern.get_locus ());
-
-HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
-ctx->insert_var_decl (stmt_id, var);
-
-locals.push_back (var);
-  }
-
   // Empty visit for unused Pattern HIR nodes.
   void visit (HIR::LiteralPattern &) override {}
   void visit (HIR::PathInExpression &) override {}
@@ -78,6 +63,7 @@ public:
   void visit (HIR::StructPattern &) override {}
   void visit (HIR::TuplePattern &) override {}
   void visit (HIR::TupleStructPattern &) override {}
+  void visit (HIR::WildcardPattern &) override {}
 
 private:
   CompileVarDecl (Context *ctx, tree fndecl, tree translated_type,
diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h 
b/gcc/rust/resolve/rust-ast-resolve-pattern.h
index 3e74f0a4cc6..4c7d13a16d0 100644
--- a/gcc/rust/resolve/rust-ast-resolve-pattern.h
+++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h
@@ -70,13 +70,6 @@ public:
   pattern.get_node_id (), pattern.get_locus (), type);
   }
 
-  void visit (AST::WildcardPattern &pattern) override
-  {
-resolver->get_name_scope ().insert (
-  CanonicalPath::new_seg (pattern.get_node_id (), "_"),
-  pattern.get_node_id (), pattern.get_locus (), type);
-  }
-
   void visit (AST::GroupedPattern &pattern) override
   {
 pattern.get_pattern_in_parens ()->accept_vis (*this);
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 55/88] gccrs: Add general TypeBounds checks

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Existing tests are updated to use libcore copy and clone implementation.

Addresses #1725

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): ensure the bounds are 
checked

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-4.rs: implement Copy trait
* rust/compile/torture/intrinsics-5.rs: likewise
* rust/execute/torture/atomic_load.rs: likewise
* rust/execute/torture/atomic_store.rs: likewise
* rust/bounds1.rs: New test.
---
 gcc/rust/typecheck/rust-unify.cc  | 11 
 gcc/testsuite/rust/bounds1.rs | 19 ++
 .../rust/compile/torture/intrinsics-4.rs  | 63 +-
 .../rust/compile/torture/intrinsics-5.rs  | 66 ++-
 .../rust/execute/torture/atomic_load.rs   | 59 -
 .../rust/execute/torture/atomic_store.rs  | 59 -
 6 files changed, 271 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/rust/bounds1.rs

diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc
index 072f76133bc..415ffcdc6ea 100644
--- a/gcc/rust/typecheck/rust-unify.cc
+++ b/gcc/rust/typecheck/rust-unify.cc
@@ -124,6 +124,17 @@ UnifyRules::go ()
   rust_debug ("unify::go ltype={%s} rtype={%s}", ltype->debug_str ().c_str (),
  rtype->debug_str ().c_str ());
 
+  // check bounds
+  if (ltype->num_specified_bounds () > 0)
+{
+  if (!ltype->bounds_compatible (*rtype, locus, true))
+   {
+ // already emitted an error
+ emit_error = false;
+ return new TyTy::ErrorType (0);
+   }
+}
+
   switch (ltype->get_kind ())
 {
 case TyTy::INFER:
diff --git a/gcc/testsuite/rust/bounds1.rs b/gcc/testsuite/rust/bounds1.rs
new file mode 100644
index 000..665836088be
--- /dev/null
+++ b/gcc/testsuite/rust/bounds1.rs
@@ -0,0 +1,19 @@
+mod core {
+mod ops {
+#[lang = "add"]
+pub trait Add {
+type Output;
+
+fn add(self, rhs: Rhs) -> Self::Output;
+}
+}
+}
+
+pub fn foo>(a: T) -> i32 {
+// { dg-error "bounds not satisfied for f32 .Add. is not satisfied" "" { 
target *-*-* } .-1 }
+a + a
+}
+
+pub fn main() {
+foo(123f32);
+}
diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs 
b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs
index 243d4460089..4e09f1089b0 100644
--- a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs
+++ b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs
@@ -1,10 +1,67 @@
-trait Copy {}
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "clone"]
+pub trait Clone: Sized {
+fn clone(&self) -> Self;
+
+fn clone_from(&mut self, source: &Self) {
+*self = source.clone()
+}
+}
+
+mod impls {
+use super::Clone;
+
+macro_rules! impl_clone {
+($($t:ty)*) => {
+$(
+impl Clone for $t {
+fn clone(&self) -> Self {
+*self
+}
+}
+)*
+}
+}
+
+impl_clone! {
+usize u8 u16 u32 u64 // u128
+isize i8 i16 i32 i64 // i128
+f32 f64
+bool char
+}
+}
+
+#[lang = "copy"]
+pub trait Copy: Clone {
+// Empty.
+}
+
+mod copy_impls {
+use super::Copy;
+
+macro_rules! impl_copy {
+($($t:ty)*) => {
+$(
+impl Copy for $t {}
+)*
+}
+}
+
+impl_copy! {
+usize u8 u16 u32 u64 // u128
+isize i8 i16 i32 i64 // i128
+f32 f64
+bool char
+}
+}
 
 extern "rust-intrinsic" {
 pub fn atomic_store_seqcst(dst: *mut T, val: T);
 pub fn atomic_store_release(dst: *mut T, val: T);
 pub fn atomic_store_relaxed(dst: *mut T, val: T);
-// pub fn atomic_store_unordered(dst: *mut T, val: T);
+pub fn atomic_store_unordered(dst: *mut T, val: T);
 }
 
 fn main() {
@@ -15,6 +72,6 @@ fn main() {
 atomic_store_seqcst(&mut dst, new_value);
 atomic_store_release(&mut dst, new_value);
 atomic_store_relaxed(&mut dst, new_value);
-// atomic_store_unordered(&mut dst, new_value);
+atomic_store_unordered(&mut dst, new_value);
 }
 }
diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs 
b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs
index 7fd84dcd635..ffad0bd3a85 100644
--- a/gcc/testsuite/rust/compile/torture/intrinsics-5.rs
+++ b/gcc/testsuite/rust/compile/torture/intrinsics-5.rs
@@ -1,4 +1,61 @@
-trait Copy {}
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "clone"]
+pub trait Clone: Sized {
+fn clone(&self) -> Self;
+
+fn clone_from(&mut self, source: &Self) {
+*self = source.clone()
+}
+}
+
+mod impls {
+use super::Clone;
+
+macro_rules! impl_clone {
+($($t:ty)*) => {
+$(
+impl Clone for $t {
+fn clone(&self) -> Self {
+   

[committed 69/88] gccrs: lex: Prevent directories in RAIIFile

2023-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

RAIIFile constructor was accepting directory filename. This lead to
unattended directory opening in some part of the code (load_file_bytes)
wich resulted in ice. Since RAIIFile are used for the lexer, removing
the ability to open directories with RAIIFile fixes those issues and
prevent future mistakes.

gcc/rust/ChangeLog:

* lex/rust-lex.h: Add file type check.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/rust/lex/rust-lex.h | 28 ++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/lex/rust-lex.h b/gcc/rust/lex/rust-lex.h
index 2dd60b365ef..50424713df9 100644
--- a/gcc/rust/lex/rust-lex.h
+++ b/gcc/rust/lex/rust-lex.h
@@ -38,13 +38,37 @@ private:
   fclose (file);
   }
 
+  static bool allowed_filetype (const struct stat &statbuf)
+  {
+// The file could be either
+// - a regular file
+// - a char device (/dev/null...)
+return S_ISREG (statbuf.st_mode) || S_ISCHR (statbuf.st_mode);
+  }
+
 public:
   RAIIFile (const char *filename) : filename (filename)
   {
 if (strcmp (filename, "-") == 0)
-  file = stdin;
+  {
+   file = stdin;
+  }
 else
-  file = fopen (filename, "r");
+  {
+   struct stat statbuf;
+   if (!(file = fopen (filename, "r")))
+ {
+   return;
+ }
+
+   if (-1 == fstat (fileno (file), &statbuf)
+   || !allowed_filetype (statbuf))
+ {
+   fclose (file);
+   file = nullptr;
+   errno = EISDIR;
+ }
+  }
   }
 
   /**
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 58/88] gccrs: parser: Expose parse_macro_invocation as public API

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* parse/rust-parse.h: Move `parse_macro_invocation` to public API.
---
 gcc/rust/parse/rust-parse.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h
index 2f767bb2a53..a4b65c50221 100644
--- a/gcc/rust/parse/rust-parse.h
+++ b/gcc/rust/parse/rust-parse.h
@@ -150,6 +150,8 @@ public:
   std::unique_ptr parse_token_tree ();
   AST::Attribute parse_attribute_body ();
   AST::AttrVec parse_inner_attributes ();
+  std::unique_ptr
+  parse_macro_invocation (AST::AttrVec outer_attrs);
 
 private:
   void skip_after_semicolon ();
@@ -201,8 +203,6 @@ private:
   parse_decl_macro_def (AST::Visibility vis, AST::AttrVec outer_attrs);
   std::unique_ptr
   parse_macro_invocation_semi (AST::AttrVec outer_attrs);
-  std::unique_ptr
-  parse_macro_invocation (AST::AttrVec outer_attrs);
   AST::MacroRule parse_macro_rule ();
   AST::MacroMatcher parse_macro_matcher ();
   std::unique_ptr parse_macro_match ();
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 56/88] gccrs: Add support for TuplePattern in let statements

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(TuplePatternItemsRanged::get_lower_patterns): Add method.
(TuplePatternItemsRanged::get_upper_patterns): Add method.
* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Implement TuplePattern visitor.
* backend/rust-compile-pattern.h
(CompilePatternLet::visit): Move TuplePattern visitor out of header 
file.

gcc/testsuite/ChangeLog:

* rust/execute/torture/let-pattern-1.rs: New test.

Signed-off-by: Owen Avery 
---
 gcc/rust/backend/rust-compile-pattern.cc  | 87 +++
 gcc/rust/backend/rust-compile-pattern.h   |  7 +-
 gcc/rust/hir/tree/rust-hir-pattern.h  | 18 
 .../rust/execute/torture/let-pattern-1.rs |  4 +
 4 files changed, 110 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/rust/execute/torture/let-pattern-1.rs

diff --git a/gcc/rust/backend/rust-compile-pattern.cc 
b/gcc/rust/backend/rust-compile-pattern.cc
index bad98be44d0..cb4b082f9c8 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -387,5 +387,92 @@ CompilePatternLet::visit (HIR::WildcardPattern &pattern)
 }
 }
 
+void
+CompilePatternLet::visit (HIR::TuplePattern &pattern)
+{
+  rust_assert (pattern.has_tuple_pattern_items ());
+
+  tree tuple_type = TyTyResolveCompile::compile (ctx, ty);
+  tree init_stmt;
+  Bvariable *tmp_var
+= ctx->get_backend ()->temporary_variable (ctx->peek_fn ().fndecl,
+  NULL_TREE, tuple_type, init_expr,
+  false, pattern.get_locus (),
+  &init_stmt);
+  tree access_expr
+= ctx->get_backend ()->var_expression (tmp_var, pattern.get_locus ());
+  ctx->add_statement (init_stmt);
+
+  switch (pattern.get_items ()->get_pattern_type ())
+{
+  case HIR::TuplePatternItems::TuplePatternItemType::RANGED: {
+   size_t tuple_idx = 0;
+   auto &items
+ = static_cast (*pattern.get_items ());
+
+   auto &items_lower = items.get_lower_patterns ();
+   auto &items_upper = items.get_upper_patterns ();
+
+   for (auto &sub : items_lower)
+ {
+   TyTy::BaseType *ty_sub = nullptr;
+   HirId pattern_id = pattern.get_pattern_mappings ().get_hirid ();
+   bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
+   rust_assert (ok);
+
+   tree sub_init = ctx->get_backend ()->struct_field_expression (
+ access_expr, tuple_idx, sub->get_locus ());
+   CompilePatternLet::Compile (sub.get (), sub_init, ty_sub,
+   rval_locus, ctx);
+   tuple_idx++;
+ }
+
+   rust_assert (ty->get_kind () == TyTy::TypeKind::TUPLE);
+   tuple_idx = static_cast (*ty).num_fields ()
+   - items_upper.size ();
+
+   for (auto &sub : items_upper)
+ {
+   TyTy::BaseType *ty_sub = nullptr;
+   HirId pattern_id = pattern.get_pattern_mappings ().get_hirid ();
+   bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
+   rust_assert (ok);
+
+   tree sub_init = ctx->get_backend ()->struct_field_expression (
+ access_expr, tuple_idx, sub->get_locus ());
+   CompilePatternLet::Compile (sub.get (), sub_init, ty_sub,
+   rval_locus, ctx);
+   tuple_idx++;
+ }
+
+   return;
+  }
+  case HIR::TuplePatternItems::TuplePatternItemType::MULTIPLE: {
+   size_t tuple_idx = 0;
+   auto &items = static_cast (
+ *pattern.get_items ());
+
+   for (auto &sub : items.get_patterns ())
+ {
+   TyTy::BaseType *ty_sub = nullptr;
+   HirId pattern_id = pattern.get_pattern_mappings ().get_hirid ();
+   bool ok = ctx->get_tyctx ()->lookup_type (pattern_id, &ty_sub);
+   rust_assert (ok);
+
+   tree sub_init = ctx->get_backend ()->struct_field_expression (
+ access_expr, tuple_idx, sub->get_locus ());
+   CompilePatternLet::Compile (sub.get (), sub_init, ty_sub,
+   rval_locus, ctx);
+   tuple_idx++;
+ }
+
+   return;
+  }
+  default: {
+   gcc_unreachable ();
+  }
+}
+}
+
 } // namespace Compile
 } // namespace Rust
diff --git a/gcc/rust/backend/rust-compile-pattern.h 
b/gcc/rust/backend/rust-compile-pattern.h
index ddf5b14265e..8f44b7b5dbb 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -101,6 +101,7 @@ public:
 
   void visit (HIR::IdentifierPattern &) override;
   void visit (HIR::WildcardPattern &) override;
+  void visit (HIR::TuplePattern &) override;
 
   // check for unimplemented Pattern HIR nodes.
   void visit (HIR::LiteralPattern &pattern) override
@@ -146,1

[committed 31/88] gccrs: parser: Improve parsing of complex generic arguments

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

The parser was missing code for handling complex type arguments such
as type paths or nested generics.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_generic_arg): Handle type
paths and nested generics properly.

gcc/testsuite/ChangeLog:

* rust/compile/parse_complex_generic_application.rs: New test.
* rust/compile/parse_complex_generic_application2.rs: New test.
---
 gcc/rust/parse/rust-parse-impl.h|  4 +++-
 .../parse_complex_generic_application.rs| 17 +
 .../parse_complex_generic_application2.rs   | 10 ++
 3 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 
gcc/testsuite/rust/compile/parse_complex_generic_application.rs
 create mode 100644 
gcc/testsuite/rust/compile/parse_complex_generic_application2.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 23b033fb26e..3610790815c 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6309,7 +6309,9 @@ Parser::parse_generic_arg ()
// could either have a valid type or a macro (FIXME: anything else?). So
// we need one bit of lookahead to differentiate if this is really
auto next_tok = lexer.peek_token (1);
-   if (next_tok->get_id () == EXCLAM)
+   if (next_tok->get_id () == LEFT_ANGLE
+   || next_tok->get_id () == SCOPE_RESOLUTION
+   || next_tok->get_id () == EXCLAM)
  {
auto type = parse_type ();
if (type)
diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application.rs 
b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs
new file mode 100644
index 000..d5c7bf488b7
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_complex_generic_application.rs
@@ -0,0 +1,17 @@
+pub enum Either {
+Left(T),
+Right(E),
+}
+
+pub mod err {
+pub struct Error;
+pub struct ErrorWrap(T);
+}
+
+pub fn foo_err() -> Either<(), err::Error> {
+Either::Left(())
+}
+
+pub fn foo_err_wrap() -> Either<(), err::ErrorWrap> {
+Either::Left(())
+}
diff --git a/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs 
b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs
new file mode 100644
index 000..0361931c50c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_complex_generic_application2.rs
@@ -0,0 +1,10 @@
+pub enum Either {
+Left(L),
+Right(R),
+}
+
+pub struct Wrap(T);
+
+pub fn foo_wrap() -> Either<(), Wrap> {
+Either::Left(())
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 81/88] gccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes, str}.rs' test cases [#1838]

2023-04-05 Thread arthur . cohen
From: Thomas Schwinge 

'dg-excess-errors' "indicates that the test is expected to fail due to compiler
messages that are not handled by 'dg-error', [etc.]".  It's argument doesn't
specify the message to match but just just a comment.  Here, however, we'd like
to match specific compiler messages, so we should use 'dg-error', etc.  Use the
magic line number zero as the compiler error diagnostic doesn't tell which line
the error occurred on (separate issue to resolve).  This gives us:

-XFAIL: rust/compile/issue-1830_str.rs (test for excess errors)
+PASS: rust/compile/issue-1830_bytes.rs  at line 8 (test for errors, line )
+PASS: rust/compile/issue-1830_bytes.rs (test for excess errors)
-XFAIL: rust/compile/issue-1830_bytes.rs (test for excess errors)
+PASS: rust/compile/issue-1830_str.rs  at line 8 (test for errors, line )
+PASS: rust/compile/issue-1830_str.rs (test for excess errors)

Fix-up for recent GCC/Rust master branch #1838
commit cf9ed4001eec6a22686d19a13f7de8ac94f9cb2a
"testsuite: Add empty string macro test".

gcc/testsuite/
* rust/compile/issue-1830_bytes.rs: Fix up DejaGnu directives.
* rust/compile/issue-1830_str.rs: Likewise.
---
 gcc/testsuite/rust/compile/issue-1830_bytes.rs | 3 ++-
 gcc/testsuite/rust/compile/issue-1830_str.rs   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/rust/compile/issue-1830_bytes.rs 
b/gcc/testsuite/rust/compile/issue-1830_bytes.rs
index dcc53b73b19..997d4ca0cdc 100644
--- a/gcc/testsuite/rust/compile/issue-1830_bytes.rs
+++ b/gcc/testsuite/rust/compile/issue-1830_bytes.rs
@@ -4,5 +4,6 @@ macro_rules! include_bytes {
 }
 
 fn main() {
-include_bytes!(""); // { dg-excess-errors "Is a directory" }
+include_bytes!("");
+// { dg-error {cannot open filename [^\n\r]+: Is a directory} {} { target 
*-*-* } 0 }
 }
diff --git a/gcc/testsuite/rust/compile/issue-1830_str.rs 
b/gcc/testsuite/rust/compile/issue-1830_str.rs
index 6cf835ba9bd..fcf2dc988d3 100644
--- a/gcc/testsuite/rust/compile/issue-1830_str.rs
+++ b/gcc/testsuite/rust/compile/issue-1830_str.rs
@@ -4,5 +4,6 @@ macro_rules! include_str {
 }
 
 fn main() {
-include_str!(""); // { dg-excess-errors "Is a directory" }
+include_str!("");
+// { dg-error {cannot open filename [^\n\r]+: Is a directory} {} { target 
*-*-* } 0 }
 }
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 79/88] gccrs: Fix formatting

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* ast/rust-pattern.h: Fix formatting.

Signed-off-by: Owen Avery 
---
 gcc/rust/ast/rust-pattern.h | 70 ++---
 1 file changed, 34 insertions(+), 36 deletions(-)

diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h
index cf5d2ead10d..0e2f56e3216 100644
--- a/gcc/rust/ast/rust-pattern.h
+++ b/gcc/rust/ast/rust-pattern.h
@@ -763,7 +763,7 @@ struct StructPatternElements
 {
 private:
   // bool has_struct_pattern_fields;
-  std::vector > fields;
+  std::vector> fields;
 
   bool has_struct_pattern_etc;
   std::vector struct_pattern_etc_attrs;
@@ -788,7 +788,7 @@ public:
 
   // Constructor for StructPatternElements with both (potentially)
   StructPatternElements (
-std::vector > fields,
+std::vector> fields,
 std::vector etc_attrs)
 : fields (std::move (fields)), has_struct_pattern_etc (true),
   struct_pattern_etc_attrs (std::move (etc_attrs))
@@ -796,7 +796,7 @@ public:
 
   // Constructor for StructPatternElements with no StructPatternEtc
   StructPatternElements (
-std::vector > fields)
+std::vector> fields)
 : fields (std::move (fields)), has_struct_pattern_etc (false),
   struct_pattern_etc_attrs ()
   {}
@@ -832,18 +832,17 @@ public:
   static StructPatternElements create_empty ()
   {
 return StructPatternElements (
-  std::vector > ());
+  std::vector> ());
   }
 
   std::string as_string () const;
 
   // TODO: seems kinda dodgy. Think of better way.
-  std::vector > &
-  get_struct_pattern_fields ()
+  std::vector> &get_struct_pattern_fields 
()
   {
 return fields;
   }
-  const std::vector > &
+  const std::vector> &
   get_struct_pattern_fields () const
   {
 return fields;
@@ -956,10 +955,10 @@ protected:
 // Class for non-ranged tuple struct pattern patterns
 class TupleStructItemsNoRange : public TupleStructItems
 {
-  std::vector > patterns;
+  std::vector> patterns;
 
 public:
-  TupleStructItemsNoRange (std::vector > patterns)
+  TupleStructItemsNoRange (std::vector> patterns)
 : patterns (std::move (patterns))
   {}
 
@@ -991,8 +990,8 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // TODO: seems kinda dodgy. Think of better way.
-  std::vector > &get_patterns () { return patterns; }
-  const std::vector > &get_patterns () const
+  std::vector> &get_patterns () { return patterns; }
+  const std::vector> &get_patterns () const
   {
 return patterns;
   }
@@ -1011,12 +1010,12 @@ protected:
 // Class for ranged tuple struct pattern patterns
 class TupleStructItemsRange : public TupleStructItems
 {
-  std::vector > lower_patterns;
-  std::vector > upper_patterns;
+  std::vector> lower_patterns;
+  std::vector> upper_patterns;
 
 public:
-  TupleStructItemsRange (std::vector > lower_patterns,
-std::vector > upper_patterns)
+  TupleStructItemsRange (std::vector> lower_patterns,
+std::vector> upper_patterns)
 : lower_patterns (std::move (lower_patterns)),
   upper_patterns (std::move (upper_patterns))
   {}
@@ -1056,21 +1055,21 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // TODO: seems kinda dodgy. Think of better way.
-  std::vector > &get_lower_patterns ()
+  std::vector> &get_lower_patterns ()
   {
 return lower_patterns;
   }
-  const std::vector > &get_lower_patterns () const
+  const std::vector> &get_lower_patterns () const
   {
 return lower_patterns;
   }
 
   // TODO: seems kinda dodgy. Think of better way.
-  std::vector > &get_upper_patterns ()
+  std::vector> &get_upper_patterns ()
   {
 return upper_patterns;
   }
-  const std::vector > &get_upper_patterns () const
+  const std::vector> &get_upper_patterns () const
   {
 return upper_patterns;
   }
@@ -1233,10 +1232,10 @@ TuplePatternItemsSingle(*this);
 // Class representing TuplePattern patterns where there are multiple patterns
 class TuplePatternItemsMultiple : public TuplePatternItems
 {
-  std::vector > patterns;
+  std::vector> patterns;
 
 public:
-  TuplePatternItemsMultiple (std::vector > patterns)
+  TuplePatternItemsMultiple (std::vector> patterns)
 : patterns (std::move (patterns))
   {}
 
@@ -1268,8 +1267,8 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // TODO: seems kinda dodgy. Think of better way.
-  std::vector > &get_patterns () { return patterns; }
-  const std::vector > &get_patterns () const
+  std::vector> &get_patterns () { return patterns; }
+  const std::vector> &get_patterns () const
   {
 return patterns;
   }
@@ -1291,13 +1290,12 @@ protected:
 // Class representing TuplePattern patterns where there are a range of patterns
 class TuplePatternItemsRanged : public TuplePatternItems
 {
-  std::vector > lower_patterns;
-  std::vector > upper_patterns;
+  std::vector> lower_patterns;
+  std::vector> upper_patterns;
 
 public:
-  TuplePatternItemsRanged (
-std::vector > lower_patterns,
-std::vector > upper_pattern

[committed 84/88] gccrs: ast: Refactor TraitItem to keep Location info

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* ast/rust-ast.h: Keep location in TraitItem base class
* ast/rust-item.h (class TraitItemFunc): Use base class location 
instead.
(class TraitItemMethod): Likewise.
(class TraitItemConst): Likewise.
(class TraitItemType): Likewise.
* ast/rust-macro.h: Likewise.
---
 gcc/rust/ast/rust-ast.h   |  6 +-
 gcc/rust/ast/rust-item.h  | 44 ++-
 gcc/rust/ast/rust-macro.h | 10 -
 3 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index d986fdf9368..585bdb09e68 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -1358,12 +1358,15 @@ protected:
 class TraitItem
 {
 protected:
-  TraitItem () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {}
+  TraitItem (Location locus)
+: node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
+  {}
 
   // Clone function implementation as pure virtual method
   virtual TraitItem *clone_trait_item_impl () const = 0;
 
   NodeId node_id;
+  Location locus;
 
 public:
   virtual ~TraitItem () {}
@@ -1382,6 +1385,7 @@ public:
   virtual bool is_marked_for_strip () const = 0;
 
   NodeId get_node_id () const { return node_id; }
+  Location get_locus () const { return locus; }
 };
 
 /* Abstract base class for items used within an inherent impl block (the impl
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 51ed815c700..16209613881 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -2908,7 +2908,6 @@ class TraitItemFunc : public TraitItem
   std::vector outer_attrs;
   TraitFunctionDecl decl;
   std::unique_ptr block_expr;
-  Location locus;
 
 public:
   // Returns whether function has a definition or is just a declaration.
@@ -2916,14 +2915,14 @@ public:
 
   TraitItemFunc (TraitFunctionDecl decl, std::unique_ptr block_expr,
 std::vector outer_attrs, Location locus)
-: TraitItem (), outer_attrs (std::move (outer_attrs)),
-  decl (std::move (decl)), block_expr (std::move (block_expr)),
-  locus (locus)
+: TraitItem (locus), outer_attrs (std::move (outer_attrs)),
+  decl (std::move (decl)), block_expr (std::move (block_expr))
   {}
 
   // Copy constructor with clone
   TraitItemFunc (TraitItemFunc const &other)
-: outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus)
+: TraitItem (other.locus), outer_attrs (other.outer_attrs),
+  decl (other.decl)
   {
 node_id = other.node_id;
 
@@ -2956,8 +2955,6 @@ public:
 
   std::string as_string () const override;
 
-  Location get_locus () const { return locus; }
-
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if trait decl is empty, so base stripping on that.
@@ -3128,7 +3125,6 @@ class TraitItemMethod : public TraitItem
   std::vector outer_attrs;
   TraitMethodDecl decl;
   std::unique_ptr block_expr;
-  Location locus;
 
 public:
   // Returns whether method has a definition or is just a declaration.
@@ -3136,14 +3132,14 @@ public:
 
   TraitItemMethod (TraitMethodDecl decl, std::unique_ptr block_expr,
   std::vector outer_attrs, Location locus)
-: TraitItem (), outer_attrs (std::move (outer_attrs)),
-  decl (std::move (decl)), block_expr (std::move (block_expr)),
-  locus (locus)
+: TraitItem (locus), outer_attrs (std::move (outer_attrs)),
+  decl (std::move (decl)), block_expr (std::move (block_expr))
   {}
 
   // Copy constructor with clone
   TraitItemMethod (TraitItemMethod const &other)
-: outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus)
+: TraitItem (other.locus), outer_attrs (other.outer_attrs),
+  decl (other.decl)
   {
 node_id = other.node_id;
 
@@ -3176,8 +3172,6 @@ public:
 
   std::string as_string () const override;
 
-  Location get_locus () const { return locus; }
-
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if trait decl is empty, so base stripping on that.
@@ -3219,8 +3213,6 @@ class TraitItemConst : public TraitItem
   // bool has_expression;
   std::unique_ptr expr;
 
-  Location locus;
-
 public:
   // Whether the constant item has an associated expression.
   bool has_expression () const { return expr != nullptr; }
@@ -3228,14 +3220,14 @@ public:
   TraitItemConst (Identifier name, std::unique_ptr type,
  std::unique_ptr expr,
  std::vector outer_attrs, Location locus)
-: TraitItem (), outer_attrs (std::move (outer_attrs)),
-  name (std::move (name)), type (std::move (type)), expr (std::move 
(expr)),
-  locus (locus)
+: TraitItem (locus), outer_attrs (std::move (outer_attrs)),
+  name (std::move (name)), type (std::move (type)), expr (std::move (expr))
   {}
 
   // Copy constructor with clones
   TraitItemConst (TraitItemConst const &other)
-: outer_attrs (other.outer_attrs), name (other.nam

[committed 82/88] gccrs: rename rust-hir-full-tests.cc

2023-04-05 Thread arthur . cohen
From: SainiAditya1 

gcc/rust/Changelog:

* hir/tree/rust-hir-full-test.cc: Moved to...
* hir/tree/rust-hir.cc: ...here.
* Make-lang.in: Rename rust-hir-full-test.

Signed-off-by: SainiAditya1 
---
 gcc/rust/Make-lang.in| 2 +-
 gcc/rust/hir/tree/{rust-hir-full-test.cc => rust-hir.cc} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename gcc/rust/hir/tree/{rust-hir-full-test.cc => rust-hir.cc} (100%)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 06f64a01dce..3ed0c09e0e7 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -86,7 +86,7 @@ GRS_OBJS = \
 rust/rust-macro-invoc-lexer.o \
 rust/rust-macro-substitute-ctx.o \
 rust/rust-macro-builtins.o \
-rust/rust-hir-full-test.o \
+rust/rust-hir.o \
 rust/rust-hir-map.o \
 rust/rust-attributes.o \
 rust/rust-abi.o \
diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc 
b/gcc/rust/hir/tree/rust-hir.cc
similarity index 100%
rename from gcc/rust/hir/tree/rust-hir-full-test.cc
rename to gcc/rust/hir/tree/rust-hir.cc
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 86/88] gccrs: Added AST Node AST::InlineAsm

2023-04-05 Thread arthur . cohen
From: M V V S Manoj Kumar 

Addresses #1567
Created a AST node InlineAsm similar to the one found in rustc.
As there is no Symbol struct/class in gccrs I have made every instance
of Symbol a string.

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (class InlineAsm):Added class declaration.
* ast/rust-expr.h (class InlineAsm):Added class definition.

Signed-off-by: M V V S Manoj Kumar 
---
 gcc/rust/ast/rust-ast-full-decls.h |   1 +
 gcc/rust/ast/rust-expr.h   | 138 +
 2 files changed, 139 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-full-decls.h 
b/gcc/rust/ast/rust-ast-full-decls.h
index 9d7b00ac5a2..64341d32641 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -149,6 +149,7 @@ struct MatchCase;
 class MatchExpr;
 class AwaitExpr;
 class AsyncBlockExpr;
+class InlineAsm;
 
 // rust-stmt.h
 class EmptyStmt;
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 3ed1885d5af..f5461848009 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4634,6 +4634,144 @@ protected:
 return new AsyncBlockExpr (*this);
   }
 };
+
+// Inline Assembly Node
+class InlineAsm : public ExprWithoutBlock
+{
+  // Inline-assembly specific options
+  enum InlineAsmOptions
+  {
+PURE = 1 << 0,
+NOMEM = 1 << 1,
+READONLY = 1 << 2,
+PRESERVES_FLAGS = 1 << 3,
+NORETURN = 1 << 4,
+NOSTACK = 1 << 5,
+ATT_SYNTAX = 1 << 6,
+RAW = 1 << 7,
+MAY_UNWIND = 1 << 8,
+  };
+
+  struct AnonConst
+  {
+NodeId id;
+std::unique_ptr value;
+  };
+
+  struct InlineAsmRegOrRegClass
+  {
+enum Type
+{
+  Reg,
+  RegClass,
+};
+
+struct Reg
+{
+  std::string Symbol;
+};
+
+struct RegClass
+{
+  std::string Symbol;
+};
+
+Identifier name;
+Location locus;
+  };
+
+  struct InlineAsmOperand
+  {
+enum RegisterType
+{
+  In,
+  Out,
+  InOut,
+  SplitInOut,
+  Const,
+  Sym,
+};
+
+struct In
+{
+  InlineAsmRegOrRegClass reg;
+  std::unique_ptr expr;
+};
+
+struct Out
+{
+  InlineAsmRegOrRegClass reg;
+  bool late;
+  std::unique_ptr expr; // can be null
+};
+
+struct InOut
+{
+  InlineAsmRegOrRegClass reg;
+  bool late;
+  std::unique_ptr expr; // this can't be null
+};
+
+struct SplitInOut
+{
+  InlineAsmRegOrRegClass reg;
+  bool late;
+  std::unique_ptr in_expr;
+  std::unique_ptr out_expr; // could be null
+};
+
+struct Const
+{
+  AnonConst anon_const;
+};
+
+struct Sym
+{
+  std::unique_ptr sym;
+};
+Location locus;
+  };
+
+  struct InlineAsmPlaceHolder
+  {
+size_t operand_idx;
+char modifier; // can be null
+Location locus;
+  };
+
+  struct InlineAsmTemplatePiece
+  {
+bool is_placeholder;
+union
+{
+  std::string string;
+  InlineAsmPlaceHolder placeholder;
+};
+  };
+
+  struct TupleClobber
+  {
+// as gccrs still doesen't contain a symbol class I have put them as 
strings
+std::string symbol;
+Location loc;
+  };
+
+  struct TupleTemplateStr
+  {
+// as gccrs still doesen't contain a symbol class I have put them as 
strings
+std::string symbol;
+std::string optional_symbol;
+Location loc;
+  };
+
+public:
+  std::vector template_;
+  std::vector template_strs;
+  std::vector operands;
+  TupleClobber clobber_abi;
+  InlineAsmOptions options;
+  std::vector line_spans;
+};
 } // namespace AST
 } // namespace Rust
 
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 40/88] gccrs: Refactor BaseType, InferType and ErrorType impl into cc file

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::BaseType): refactor
(BaseType::~BaseType): likewise
(BaseType::get_ref): likewise
(BaseType::set_ref): likewise
(BaseType::get_ty_ref): likewise
(BaseType::set_ty_ref): likewise
(BaseType::is_equal): likewise
(BaseType::is_unit): likewise
(BaseType::get_kind): likewise
(BaseType::get_combined_refs): likewise
(BaseType::append_reference): likewise
(BaseType::supports_substitutions): likewise
(BaseType::has_subsititions_defined): likewise
(BaseType::can_substitute): likewise
(BaseType::needs_generic_substitutions): likewise
(BaseType::contains_type_parameters): likewise
(BaseType::get_ident): likewise
(BaseType::get_locus): likewise
(InferType::InferType): likewise
(InferType::get_infer_kind): likewise
(InferType::get_name): likewise
(InferType::is_concrete): likewise
(ErrorType::ErrorType): likewise
(ErrorType::is_unit): likewise
(ErrorType::is_concrete): likewise
(ErrorType::get_name): likewise
(ErrorType::monomorphized_clone): likewise
* typecheck/rust-tyty.h (class SubstitutionArgumentMappings): likewise
---
 gcc/rust/typecheck/rust-tyty.cc | 181 
 gcc/rust/typecheck/rust-tyty.h  |  92 ++--
 2 files changed, 211 insertions(+), 62 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index b45bd99b1bd..079055e870d 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -146,6 +146,122 @@ is_primitive_type_kind (TypeKind kind)
 }
 }
 
+// BASE TYPE
+
+BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident,
+   std::set refs)
+  : TypeBoundsMappings ({}), kind (kind), ref (ref), ty_ref (ty_ref),
+combined (refs), ident (ident), mappings (Analysis::Mappings::get ())
+{}
+
+BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident,
+   std::vector specified_bounds,
+   std::set refs)
+  : TypeBoundsMappings (specified_bounds), kind (kind), ref (ref),
+ty_ref (ty_ref), combined (refs), ident (ident),
+mappings (Analysis::Mappings::get ())
+{}
+
+BaseType::~BaseType () {}
+
+HirId
+BaseType::get_ref () const
+{
+  return ref;
+}
+
+void
+BaseType::set_ref (HirId id)
+{
+  if (id != ref)
+append_reference (ref);
+  ref = id;
+}
+
+HirId
+BaseType::get_ty_ref () const
+{
+  return ty_ref;
+}
+
+void
+BaseType::set_ty_ref (HirId id)
+{
+  ty_ref = id;
+}
+
+bool
+BaseType::is_equal (const BaseType &other) const
+{
+  return get_kind () == other.get_kind ();
+}
+
+bool
+BaseType::is_unit () const
+{
+  return false;
+}
+
+TypeKind
+BaseType::get_kind () const
+{
+  return kind;
+}
+
+std::set
+BaseType::get_combined_refs () const
+{
+  return combined;
+}
+
+void
+BaseType::append_reference (HirId id)
+{
+  combined.insert (id);
+}
+
+bool
+BaseType::supports_substitutions () const
+{
+  return false;
+}
+
+bool
+BaseType::has_subsititions_defined () const
+{
+  return false;
+}
+
+bool
+BaseType::can_substitute () const
+{
+  return supports_substitutions () && has_subsititions_defined ();
+}
+
+bool
+BaseType::needs_generic_substitutions () const
+{
+  return false;
+}
+
+bool
+BaseType::contains_type_parameters () const
+{
+  return !is_concrete ();
+}
+
+const RustIdent &
+BaseType::get_ident () const
+{
+  return ident;
+}
+
+Location
+BaseType::get_locus () const
+{
+  return ident.locus;
+}
+
 bool
 BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const
 {
@@ -330,6 +446,40 @@ BaseType::debug () const
  debug_str ().c_str ());
 }
 
+// InferType
+
+InferType::InferType (HirId ref, InferTypeKind infer_kind, Location locus,
+ std::set refs)
+  : BaseType (ref, ref, TypeKind::INFER,
+ {Resolver::CanonicalPath::create_empty (), locus}, refs),
+infer_kind (infer_kind)
+{}
+
+InferType::InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind,
+ Location locus, std::set refs)
+  : BaseType (ref, ty_ref, TypeKind::INFER,
+ {Resolver::CanonicalPath::create_empty (), locus}, refs),
+infer_kind (infer_kind)
+{}
+
+InferType::InferTypeKind
+InferType::get_infer_kind () const
+{
+  return infer_kind;
+}
+
+std::string
+InferType::get_name () const
+{
+  return as_string ();
+}
+
+bool
+InferType::is_concrete () const
+{
+  return true;
+}
+
 void
 InferType::accept_vis (TyVisitor &vis)
 {
@@ -435,6 +585,35 @@ InferType::default_type (BaseType **type) const
   return false;
 }
 
+// ErrorType
+
+ErrorType::ErrorType (HirId ref, std::set refs)
+  : BaseType (ref, ref, TypeKind::ERROR,
+ {Resolver::CanonicalPath::create_empty (), Location ()}, refs)
+{}
+
+ErrorType:

[committed 39/88] gccrs: Refactor all substitution mapper code implementation into its own CC file

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-substitution-mapper.cc (SubstMapper::SubstMapper): 
refactor
(SubstMapper::Resolve): likewise
(SubstMapper::InferSubst): likewise
(SubstMapper::have_generic_args): likewise
(SubstMapper::visit): likewise
(SubstMapperInternal::visit): likewise
(SubstMapperFromExisting::SubstMapperFromExisting): likewise
(SubstMapperFromExisting::Resolve): likewise
(SubstMapperFromExisting::visit): likewise
(GetUsedSubstArgs::GetUsedSubstArgs): likewise
(GetUsedSubstArgs::From): likewise
(GetUsedSubstArgs::visit): likewise
* typecheck/rust-substitution-mapper.h: refactor
* typecheck/rust-tyty-subst.cc 
(SubstitutionParamMapping::get_generic_param): likewise
---
 .../typecheck/rust-substitution-mapper.cc | 343 ++
 gcc/rust/typecheck/rust-substitution-mapper.h | 286 +++
 gcc/rust/typecheck/rust-tyty-subst.cc |   2 +-
 3 files changed, 387 insertions(+), 244 deletions(-)

diff --git a/gcc/rust/typecheck/rust-substitution-mapper.cc 
b/gcc/rust/typecheck/rust-substitution-mapper.cc
index e1d988818bb..dc93857e60f 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.cc
+++ b/gcc/rust/typecheck/rust-substitution-mapper.cc
@@ -22,6 +22,116 @@
 namespace Rust {
 namespace Resolver {
 
+SubstMapper::SubstMapper (HirId ref, HIR::GenericArgs *generics, Location 
locus)
+  : resolved (new TyTy::ErrorType (ref)), generics (generics), locus (locus)
+{}
+
+TyTy::BaseType *
+SubstMapper::Resolve (TyTy::BaseType *base, Location locus,
+ HIR::GenericArgs *generics)
+{
+  SubstMapper mapper (base->get_ref (), generics, locus);
+  base->accept_vis (mapper);
+  rust_assert (mapper.resolved != nullptr);
+  return mapper.resolved;
+}
+
+TyTy::BaseType *
+SubstMapper::InferSubst (TyTy::BaseType *base, Location locus)
+{
+  return SubstMapper::Resolve (base, locus, nullptr);
+}
+
+bool
+SubstMapper::have_generic_args () const
+{
+  return generics != nullptr;
+}
+
+void
+SubstMapper::visit (TyTy::FnType &type)
+{
+  TyTy::FnType *concrete = nullptr;
+  if (!have_generic_args ())
+{
+  TyTy::BaseType *substs = type.infer_substitions (locus);
+  rust_assert (substs->get_kind () == TyTy::TypeKind::FNDEF);
+  concrete = static_cast (substs);
+}
+  else
+{
+  TyTy::SubstitutionArgumentMappings mappings
+   = type.get_mappings_from_generic_args (*generics);
+  if (mappings.is_error ())
+   return;
+
+  concrete = type.handle_substitions (mappings);
+}
+
+  if (concrete != nullptr)
+resolved = concrete;
+}
+
+void
+SubstMapper::visit (TyTy::ADTType &type)
+{
+  TyTy::ADTType *concrete = nullptr;
+  if (!have_generic_args ())
+{
+  TyTy::BaseType *substs = type.infer_substitions (locus);
+  rust_assert (substs->get_kind () == TyTy::TypeKind::ADT);
+  concrete = static_cast (substs);
+}
+  else
+{
+  TyTy::SubstitutionArgumentMappings mappings
+   = type.get_mappings_from_generic_args (*generics);
+  if (mappings.is_error ())
+   return;
+
+  concrete = type.handle_substitions (mappings);
+}
+
+  if (concrete != nullptr)
+resolved = concrete;
+}
+
+void
+SubstMapper::visit (TyTy::PlaceholderType &type)
+{
+  rust_assert (type.can_resolve ());
+  resolved = SubstMapper::Resolve (type.resolve (), locus, generics);
+}
+
+void
+SubstMapper::visit (TyTy::ProjectionType &type)
+{
+  TyTy::ProjectionType *concrete = nullptr;
+  if (!have_generic_args ())
+{
+  TyTy::BaseType *substs = type.infer_substitions (locus);
+  rust_assert (substs->get_kind () == TyTy::TypeKind::PROJECTION);
+  concrete = static_cast (substs);
+}
+  else
+{
+  TyTy::SubstitutionArgumentMappings mappings
+   = type.get_mappings_from_generic_args (*generics);
+  if (mappings.is_error ())
+   return;
+
+  concrete = type.handle_substitions (mappings);
+}
+
+  if (concrete != nullptr)
+resolved = concrete;
+}
+
+SubstMapperInternal::SubstMapperInternal (
+  HirId ref, TyTy::SubstitutionArgumentMappings &mappings)
+  : resolved (new TyTy::ErrorType (ref)), mappings (mappings)
+{}
+
 TyTy::BaseType *
 SubstMapperInternal::Resolve (TyTy::BaseType *base,
  TyTy::SubstitutionArgumentMappings &mappings)
@@ -73,5 +183,238 @@ SubstMapperInternal::mappings_are_bound (
   return false;
 }
 
+void
+SubstMapperInternal::visit (TyTy::FnType &type)
+{
+  TyTy::SubstitutionArgumentMappings adjusted
+= type.adjust_mappings_for_this (mappings);
+  if (adjusted.is_error ())
+return;
+
+  TyTy::BaseType *concrete = type.handle_substitions (adjusted);
+  if (concrete != nullptr)
+resolved = concrete;
+}
+
+void
+SubstMapperInternal::visit (TyTy::ADTType &type)
+{
+  TyTy::SubstitutionArgumentMappings adjusted
+= type.adjust_mappings_for_this (mappings);
+  i

[committed 44/88] gccrs: Rename rust-tyctx.cc to rust-typecheck-context.cc

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* Make-lang.in: update name
* typecheck/rust-tyctx.cc: Moved to...
* typecheck/rust-typecheck-context.cc: ...here.
---
 gcc/rust/Make-lang.in   | 2 +-
 gcc/rust/typecheck/{rust-tyctx.cc => rust-typecheck-context.cc} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename gcc/rust/typecheck/{rust-tyctx.cc => rust-typecheck-context.cc} (100%)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 5e173f1d2dc..4752bb83562 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -118,7 +118,7 @@ GRS_OBJS = \
 rust/rust-tyty-util.o \
 rust/rust-tyty-call.o \
 rust/rust-tyty-subst.o \
-rust/rust-tyctx.o \
+rust/rust-typecheck-context.o \
 rust/rust-tyty-bounds.o \
 rust/rust-hir-type-check-util.o \
 rust/rust-hir-trait-resolve.o \
diff --git a/gcc/rust/typecheck/rust-tyctx.cc 
b/gcc/rust/typecheck/rust-typecheck-context.cc
similarity index 100%
rename from gcc/rust/typecheck/rust-tyctx.cc
rename to gcc/rust/typecheck/rust-typecheck-context.cc
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 45/88] gccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-ref.h: Moved to...
* typecheck/rust-hir-trait-reference.h: ...here.
* typecheck/rust-hir-trait-resolve.cc: refactor
* typecheck/rust-hir-trait-resolve.h (RUST_HIR_TRAIT_RESOLVE_H): 
likewise
* typecheck/rust-hir-type-check.h: likewise
* typecheck/rust-tyty.cc: likewise
---
 ...rust-hir-trait-ref.h => rust-hir-trait-reference.h} |  0
 gcc/rust/typecheck/rust-hir-trait-resolve.cc   | 10 ++
 gcc/rust/typecheck/rust-hir-trait-resolve.h|  9 +
 gcc/rust/typecheck/rust-hir-type-check.h   |  2 +-
 gcc/rust/typecheck/rust-tyty.cc|  2 +-
 5 files changed, 13 insertions(+), 10 deletions(-)
 rename gcc/rust/typecheck/{rust-hir-trait-ref.h => rust-hir-trait-reference.h} 
(100%)

diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h 
b/gcc/rust/typecheck/rust-hir-trait-reference.h
similarity index 100%
rename from gcc/rust/typecheck/rust-hir-trait-ref.h
rename to gcc/rust/typecheck/rust-hir-trait-reference.h
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc 
b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 19f95ca4488..e2d0cf2d7a2 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -22,6 +22,16 @@
 namespace Rust {
 namespace Resolver {
 
+TraitItemReference
+ResolveTraitItemToRef::Resolve (
+  HIR::TraitItem &item, TyTy::BaseType *self,
+  std::vector substitutions)
+{
+  ResolveTraitItemToRef resolver (self, std::move (substitutions));
+  item.accept_vis (resolver);
+  return std::move (resolver.resolved);
+}
+
 void
 ResolveTraitItemToRef::visit (HIR::TraitItemType &type)
 {
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.h 
b/gcc/rust/typecheck/rust-hir-trait-resolve.h
index ca23d48c3dd..da8e2c0b838 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.h
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.h
@@ -19,9 +19,7 @@
 #ifndef RUST_HIR_TRAIT_RESOLVE_H
 #define RUST_HIR_TRAIT_RESOLVE_H
 
-#include "rust-hir-type-check-base.h"
 #include "rust-hir-type-check-type.h"
-#include "rust-hir-trait-ref.h"
 
 namespace Rust {
 namespace Resolver {
@@ -32,12 +30,7 @@ class ResolveTraitItemToRef : public TypeCheckBase,
 public:
   static TraitItemReference
   Resolve (HIR::TraitItem &item, TyTy::BaseType *self,
-  std::vector substitutions)
-  {
-ResolveTraitItemToRef resolver (self, std::move (substitutions));
-item.accept_vis (resolver);
-return std::move (resolver.resolved);
-  }
+  std::vector substitutions);
 
   void visit (HIR::TraitItemType &type) override;
 
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h 
b/gcc/rust/typecheck/rust-hir-type-check.h
index d1eb750a621..512453947a6 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -22,7 +22,7 @@
 #include "rust-hir-full-decls.h"
 #include "rust-hir-map.h"
 #include "rust-tyty.h"
-#include "rust-hir-trait-ref.h"
+#include "rust-hir-trait-reference.h"
 #include "rust-autoderef.h"
 
 namespace Rust {
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 61c02a85c53..4c324c66c16 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -27,7 +27,7 @@
 #include "rust-linemap.h"
 
 #include "rust-substitution-mapper.h"
-#include "rust-hir-trait-ref.h"
+#include "rust-hir-trait-reference.h"
 #include "rust-hir-type-bounds.h"
 #include "rust-hir-trait-resolve.h"
 #include "rust-tyty-rules.h"
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 54/88] gccrs: Remove bad error message on checking function arguments

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove error 
message

gcc/testsuite/ChangeLog:

* rust/compile/func3.rs: update test case
---
 gcc/rust/typecheck/rust-tyty-call.cc | 5 -
 gcc/testsuite/rust/compile/func3.rs  | 1 -
 2 files changed, 6 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-call.cc 
b/gcc/rust/typecheck/rust-tyty-call.cc
index 4c6442e2d82..67e2866cbce 100644
--- a/gcc/rust/typecheck/rust-tyty-call.cc
+++ b/gcc/rust/typecheck/rust-tyty-call.cc
@@ -140,8 +140,6 @@ TypeCheckCallExpr::visit (FnType &type)
argument->get_locus ());
  if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (argument->get_locus (),
-"Type Resolution failure on parameter");
  return;
}
}
@@ -193,8 +191,6 @@ TypeCheckCallExpr::visit (FnPtr &type)
TyWithLocation (argument_expr_tyty, arg_locus), argument->get_locus ());
   if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (argument->get_locus (),
-"Type Resolution failure on parameter");
  return;
}
 
@@ -301,7 +297,6 @@ TypeCheckMethodCallExpr::check (FnType &type)
TyWithLocation (argument_expr_tyty, arg_locus), arg_locus);
   if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (arg_locus, "Type Resolution failure on parameter");
  return new ErrorType (type.get_ref ());
}
 
diff --git a/gcc/testsuite/rust/compile/func3.rs 
b/gcc/testsuite/rust/compile/func3.rs
index 2a329476118..002e5c90ab5 100644
--- a/gcc/testsuite/rust/compile/func3.rs
+++ b/gcc/testsuite/rust/compile/func3.rs
@@ -5,5 +5,4 @@ fn test(a: i32, b: i32) -> i32 {
 fn main() {
 let a = test(1, true);
 // { dg-error "expected .i32. got .bool." "" { target *-*-* } .-1 }
-// { dg-error "Type Resolution failure on parameter" "" { target *-*-* } 
.-2 }
 }
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 42/88] gccrs: Refactor PathProbeType code into CC file

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc 
(PathProbeCandidate::Candidate::Candidate): refactor
(PathProbeCandidate::PathProbeCandidate): likewise
(PathProbeCandidate::as_string): likewise
(PathProbeCandidate::is_enum_candidate): likewise
(PathProbeCandidate::is_impl_candidate): likewise
(PathProbeCandidate::is_trait_candidate): likewise
(PathProbeCandidate::is_full_trait_item_candidate): likewise
(PathProbeCandidate::get_error): likewise
(PathProbeCandidate::is_error): likewise
(PathProbeCandidate::get_defid): likewise
(PathProbeCandidate::operator<): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise
---
 gcc/rust/typecheck/rust-hir-path-probe.cc | 109 ++
 gcc/rust/typecheck/rust-hir-path-probe.h  |  82 +++-
 2 files changed, 124 insertions(+), 67 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc 
b/gcc/rust/typecheck/rust-hir-path-probe.cc
index 06d8920d2eb..be89ceb8645 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -23,6 +23,115 @@
 namespace Rust {
 namespace Resolver {
 
+// PathProbeCandidate
+
+PathProbeCandidate::Candidate::Candidate (EnumItemCandidate enum_field)
+  : enum_field (enum_field)
+{}
+
+PathProbeCandidate::Candidate::Candidate (ImplItemCandidate impl) : impl (impl)
+{}
+
+PathProbeCandidate::Candidate::Candidate (TraitItemCandidate trait)
+  : trait (trait)
+{}
+
+PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty,
+   Location locus,
+   EnumItemCandidate enum_field)
+  : type (type), ty (ty), locus (locus), item (enum_field)
+{}
+
+PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty,
+   Location locus, ImplItemCandidate impl)
+  : type (type), ty (ty), locus (locus), item (impl)
+{}
+
+PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty,
+   Location locus,
+   TraitItemCandidate trait)
+  : type (type), ty (ty), locus (locus), item (trait)
+{}
+
+std::string
+PathProbeCandidate::as_string () const
+{
+  return "PathProbe candidate TODO - as_string";
+}
+
+bool
+PathProbeCandidate::is_enum_candidate () const
+{
+  return type == ENUM_VARIANT;
+}
+
+bool
+PathProbeCandidate::is_impl_candidate () const
+{
+  return type == IMPL_CONST || type == IMPL_TYPE_ALIAS || type == IMPL_FUNC;
+}
+
+bool
+PathProbeCandidate::is_trait_candidate () const
+{
+  return type == TRAIT_ITEM_CONST || type == TRAIT_TYPE_ALIAS
+|| type == TRAIT_FUNC;
+}
+
+bool
+PathProbeCandidate::is_full_trait_item_candidate () const
+{
+  return is_trait_candidate () && item.trait.impl == nullptr;
+}
+
+PathProbeCandidate
+PathProbeCandidate::get_error ()
+{
+  return PathProbeCandidate (ERROR, nullptr, Location (),
+ImplItemCandidate{nullptr, nullptr});
+}
+
+bool
+PathProbeCandidate::is_error () const
+{
+  return type == ERROR;
+}
+
+DefId
+PathProbeCandidate::get_defid () const
+{
+  switch (type)
+{
+case ENUM_VARIANT:
+  return item.enum_field.variant->get_defid ();
+  break;
+
+case IMPL_CONST:
+case IMPL_TYPE_ALIAS:
+case IMPL_FUNC:
+  return item.impl.impl_item->get_impl_mappings ().get_defid ();
+  break;
+
+case TRAIT_ITEM_CONST:
+case TRAIT_TYPE_ALIAS:
+case TRAIT_FUNC:
+  return item.trait.item_ref->get_mappings ().get_defid ();
+  break;
+
+case ERROR:
+default:
+  return UNKNOWN_DEFID;
+}
+
+  return UNKNOWN_DEFID;
+}
+
+bool
+PathProbeCandidate::operator< (const PathProbeCandidate &c) const
+{
+  return get_defid () < c.get_defid ();
+}
+
 // PathProbeType
 
 PathProbeType::PathProbeType (const TyTy::BaseType *receiver,
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h 
b/gcc/rust/typecheck/rust-hir-path-probe.h
index 783282a0dc9..dd511ac4184 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -73,89 +73,37 @@ struct PathProbeCandidate
 ImplItemCandidate impl;
 TraitItemCandidate trait;
 
-Candidate (EnumItemCandidate enum_field) : enum_field (enum_field) {}
-Candidate (ImplItemCandidate impl) : impl (impl) {}
-Candidate (TraitItemCandidate trait) : trait (trait) {}
+Candidate (EnumItemCandidate enum_field);
+Candidate (ImplItemCandidate impl);
+Candidate (TraitItemCandidate trait);
   } item;
 
   PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus,
- EnumItemCandidate enum_field)
-: type (type), ty (ty), locus (locus), item (enum_field)
-  {}
+ EnumItemCandidate enum_field);
 
   PathProbe

[committed 61/88] gccrs: expander: Add documentation for `expand_eager_invocations`

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add documentation explaining the algorithm.
---
 gcc/rust/expand/rust-macro-expand.cc | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index 0ff849dc85d..4b494490424 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -197,17 +197,25 @@ MacroExpander::expand_eager_invocations 
(AST::MacroInvocation &invoc)
   auto start = kv.first.first;
   auto end = kv.first.second;
 
-  // TODO: Add doc
+  // We're now going to re-add the tokens to the invocation's token tree.
+  // 1. Basically, what we want to do is insert all tokens up until the
+  //beginning of the macro invocation (start).
+  // 2. Then, we'll insert all of the tokens resulting from the macro
+  //expansion: These are in `new_tokens`.
+  // 3. Finally, we'll do that again from
+  //the end of macro and go back to 1.
+
   for (size_t i = current_idx; i < start; i++)
new_stream.emplace_back (stream[i]->clone_token ());
 
-  // TODO: Add doc
   for (auto &tok : new_tokens)
new_stream.emplace_back (tok->clone_token ());
 
   current_idx = end;
 }
-  // TODO: Add doc
+
+  // Once all of that is done, we copy the last remaining tokens from the
+  // original stream
   for (size_t i = current_idx; i < stream.size (); i++)
 new_stream.emplace_back (stream[i]->clone_token ());
 
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 64/88] gccrs: Update copyright years.

2023-04-05 Thread arthur . cohen
From: Thomas Schwinge 

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.cc: Update copyright years.
* ast/rust-ast-fragment.h: Likewise.
* ast/rust-macro.cc: Likewise.
* checks/errors/rust-feature-gate.cc: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* checks/errors/rust-feature.cc: Likewise.
* checks/errors/rust-feature.h: Likewise.
* hir/rust-ast-lower-expr.cc: Likewise.
* hir/rust-ast-lower-type.cc: Likewise.
* resolve/rust-early-name-resolver.cc: Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* rust-gcc.h: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-tyty-bounds.h: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty-subst.h: Likewise.
* typecheck/rust-tyty-util.cc: Likewise.
* typecheck/rust-tyty-util.h: Likewise.
* typecheck/rust-unify.cc: Likewise.
* typecheck/rust-unify.h: Likewise.
* util/rust-inline-visitor.h: Likewise.
---
 gcc/rust/ast/rust-ast-fragment.cc  | 2 +-
 gcc/rust/ast/rust-ast-fragment.h   | 2 +-
 gcc/rust/ast/rust-macro.cc | 2 +-
 gcc/rust/checks/errors/rust-feature-gate.cc| 2 +-
 gcc/rust/checks/errors/rust-feature-gate.h | 2 +-
 gcc/rust/checks/errors/rust-feature.cc | 2 +-
 gcc/rust/checks/errors/rust-feature.h  | 2 +-
 gcc/rust/hir/rust-ast-lower-expr.cc| 2 +-
 gcc/rust/hir/rust-ast-lower-type.cc| 2 +-
 gcc/rust/resolve/rust-early-name-resolver.cc   | 2 +-
 gcc/rust/resolve/rust-early-name-resolver.h| 2 +-
 gcc/rust/rust-gcc.h| 2 +-
 gcc/rust/typecheck/rust-hir-path-probe.cc  | 2 +-
 gcc/rust/typecheck/rust-hir-trait-reference.cc | 2 +-
 gcc/rust/typecheck/rust-tyty-bounds.h  | 2 +-
 gcc/rust/typecheck/rust-tyty-subst.cc  | 2 +-
 gcc/rust/typecheck/rust-tyty-subst.h   | 2 +-
 gcc/rust/typecheck/rust-tyty-util.cc   | 2 +-
 gcc/rust/typecheck/rust-tyty-util.h| 2 +-
 gcc/rust/typecheck/rust-unify.cc   | 2 +-
 gcc/rust/typecheck/rust-unify.h| 2 +-
 gcc/rust/util/rust-inline-visitor.h| 2 +-
 22 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-fragment.cc 
b/gcc/rust/ast/rust-ast-fragment.cc
index fba629c0119..a9dc4747d51 100644
--- a/gcc/rust/ast/rust-ast-fragment.cc
+++ b/gcc/rust/ast/rust-ast-fragment.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h
index 22e99090b25..41f5a287756 100644
--- a/gcc/rust/ast/rust-ast-fragment.h
+++ b/gcc/rust/ast/rust-ast-fragment.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/ast/rust-macro.cc b/gcc/rust/ast/rust-macro.cc
index b90cc15898e..b6f8f6c059a 100644
--- a/gcc/rust/ast/rust-macro.cc
+++ b/gcc/rust/ast/rust-macro.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc 
b/gcc/rust/checks/errors/rust-feature-gate.cc
index cd26f8a17f5..31ce3679ee1 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/rust-feature-gate.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 080c15ccd23..dc95c6b3879 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/rust-feature.cc 
b/gcc/rust/checks/errors/rust-feature.cc
index b87b4ca38ef..81689d9302b 100644
--- a/gcc/rust/checks/errors/rust-feature.cc
+++ b/gcc/rust/checks/errors/rust-feature.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
 
 // This file is part of GCC.
 
diff --git a/gcc/rust/checks/errors/rust-feature.h 
b/gcc/rust/checks/errors/rust-feature.h
index bf93b090af5..1425e26cd9a 100644
--- a/gcc/rust/checks/errors/rust-feature.h
+++ b/gcc/rust/checks/errors/rust-feature.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 

[committed 50/88] gccrs: Refactor the type unification code

2023-04-05 Thread arthur . cohen
From: Philip Herron 

This refactors the unification systems to be a consistent interface using
switch statements and simple functions instead of the old clunky visitor
system. This is more maintainable as it is harder to miss cases when we
can take advantages of switch statements.

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* Make-lang.in: update names
* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address):
update to use new interface
* typecheck/rust-coercion.cc 
(TypeCoercionRules::coerce_borrowed_pointer): likewise
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): 
likewise
* typecheck/rust-tyty.cc (BaseType::destructure): likewise
(InferType::unify): removed old unify interface
(ErrorType::unify): likewise
(ADTType::unify): likewise
(TupleType::unify): likewise
(FnType::unify): likewise
(FnPtr::unify): likewise
(ClosureType::unify): likewise
(ArrayType::unify): likewise
(SliceType::unify): likewise
(BoolType::unify): likewise
(IntType::unify): likewise
(UintType::unify): likewise
(FloatType::unify): likewise
(USizeType::unify): likewise
(ISizeType::unify): likewise
(CharType::unify): likewise
(ReferenceType::unify): likewise
(PointerType::unify): likewise
(ParamType::unify): likewise
(StrType::unify): likewise
(NeverType::unify): likewise
(PlaceholderType::unify): likewise
(ProjectionType::unify): likewise
(DynamicObjectType::unify): likewise
* typecheck/rust-tyty.h: update destructure interface
* typecheck/rust-tyty-rules.h: Removed.
* typecheck/rust-unify.cc: New file.
* typecheck/rust-unify.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/never_type_err1.rs: Moved to...
* rust/compile/never_type1.rs: ...here. It now works
---
 gcc/rust/Make-lang.in |1 +
 gcc/rust/backend/rust-compile-expr.cc |6 +-
 gcc/rust/typecheck/rust-coercion.cc   |6 +-
 .../typecheck/rust-hir-type-check-base.cc |   15 +-
 gcc/rust/typecheck/rust-tyty-rules.h  | 1406 --
 gcc/rust/typecheck/rust-tyty.cc   |  229 +--
 gcc/rust/typecheck/rust-tyty.h|   31 +-
 gcc/rust/typecheck/rust-unify.cc  | 1640 +
 gcc/rust/typecheck/rust-unify.h   |   91 +
 .../{never_type_err1.rs => never_type1.rs}|3 +-
 10 files changed, 1807 insertions(+), 1621 deletions(-)
 delete mode 100644 gcc/rust/typecheck/rust-tyty-rules.h
 create mode 100644 gcc/rust/typecheck/rust-unify.cc
 create mode 100644 gcc/rust/typecheck/rust-unify.h
 rename gcc/testsuite/rust/compile/{never_type_err1.rs => never_type1.rs} (52%)

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 4752bb83562..1d2f34d7919 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -134,6 +134,7 @@ GRS_OBJS = \
 rust/rust-hir-path-probe.o \
 rust/rust-coercion.o \
 rust/rust-casts.o \
+rust/rust-unify.o \
 rust/rust-hir-type-check-base.o \
 rust/rust-autoderef.o \
 rust/rust-substitution-mapper.o \
diff --git a/gcc/rust/backend/rust-compile-expr.cc 
b/gcc/rust/backend/rust-compile-expr.cc
index c26f6f440ec..d7945dbf26b 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -26,6 +26,7 @@
 #include "rust-compile-block.h"
 #include "rust-compile-implitem.h"
 #include "rust-constexpr.h"
+#include "rust-unify.h"
 #include "rust-gcc.h"
 
 #include "fold-const.h"
@@ -2006,7 +2007,10 @@ CompileExpr::resolve_method_address (TyTy::FnType 
*fntype, HirId ref,
{
  TyTy::BaseType *infer_impl_call
= candidate_call->infer_substitions (expr_locus);
- monomorphized = infer_impl_call->unify (fntype);
+ monomorphized = Resolver::UnifyRules::Resolve (
+   TyTy::TyWithLocation (infer_impl_call),
+   TyTy::TyWithLocation (fntype), expr_locus, true /* commit */,
+   true /* emit_errors */);
}
 
   return CompileInherentImplItem::Compile (impl_item, ctx, monomorphized);
diff --git a/gcc/rust/typecheck/rust-coercion.cc 
b/gcc/rust/typecheck/rust-coercion.cc
index fdf8eb95a33..bea40840fbf 100644
--- a/gcc/rust/typecheck/rust-coercion.cc
+++ b/gcc/rust/typecheck/rust-coercion.cc
@@ -18,6 +18,7 @@
 
 #include "rust-hir-type-check-base.h"
 #include "rust-coercion.h"
+#include "rust-unify.h"
 
 namespace Rust {
 namespace Resolver {
@@ -218,7 +219,10 @@ TypeCoercionRules::coerce_borrowed_pointer (TyTy::BaseType 
*receiver,
// we might be able to replace this with a can_eq because we default
// back to a final unity anyway
rust_debug ("coerce_borrowed_pointer -- unify");
-   TyTy::BaseType *result = receiver->unify (expected);
+   TyTy::BaseTy

[committed 59/88] gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::get_token_slice):
Add API to retrieve token slices when lexing macro expansions.
* expand/rust-macro-invoc-lexer.h: Declare `get_token_slice`.
---
 gcc/rust/expand/rust-macro-invoc-lexer.cc | 14 ++
 gcc/rust/expand/rust-macro-invoc-lexer.h  |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.cc 
b/gcc/rust/expand/rust-macro-invoc-lexer.cc
index 8a43d29e0d1..321f0f97a76 100644
--- a/gcc/rust/expand/rust-macro-invoc-lexer.cc
+++ b/gcc/rust/expand/rust-macro-invoc-lexer.cc
@@ -26,4 +26,18 @@ MacroInvocLexer::split_current_token (TokenId new_left 
__attribute__ ((unused)),
   // FIXME
   gcc_unreachable ();
 }
+
+std::vector>
+MacroInvocLexer::get_token_slice (size_t start_idx, size_t end_idx) const
+{
+  std::vector> slice;
+
+  rust_assert (end_idx < token_stream.size ());
+
+  for (size_t i = start_idx; i < end_idx; i++)
+slice.emplace_back (token_stream[i]->clone_token ());
+
+  return slice;
+}
+
 } // namespace Rust
diff --git a/gcc/rust/expand/rust-macro-invoc-lexer.h 
b/gcc/rust/expand/rust-macro-invoc-lexer.h
index a0d30164850..0923c18c84d 100644
--- a/gcc/rust/expand/rust-macro-invoc-lexer.h
+++ b/gcc/rust/expand/rust-macro-invoc-lexer.h
@@ -55,6 +55,9 @@ public:
 
   size_t get_offs () const { return offs; }
 
+  std::vector>
+  get_token_slice (size_t start_idx, size_t end_idx) const;
+
 private:
   size_t offs;
   std::vector> token_stream;
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 73/88] gccrs: Extract query_type from TypeCheckBase to be a simple extern

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* Make-lang.in: add new dependancy
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): 
refactor
* typecheck/rust-hir-type-check-base.h: refactor
* typecheck/rust-hir-type-check.h (RUST_HIR_TYPE_CHECK): refactor
* typecheck/rust-type-util.cc: New file.
* typecheck/rust-type-util.h: New file.
---
 gcc/rust/Make-lang.in |   1 +
 .../typecheck/rust-hir-type-check-base.cc |  73 
 gcc/rust/typecheck/rust-hir-type-check-base.h |   2 -
 gcc/rust/typecheck/rust-hir-type-check.h  |   1 +
 gcc/rust/typecheck/rust-type-util.cc  | 108 ++
 gcc/rust/typecheck/rust-type-util.h   |  38 ++
 6 files changed, 148 insertions(+), 75 deletions(-)
 create mode 100644 gcc/rust/typecheck/rust-type-util.cc
 create mode 100644 gcc/rust/typecheck/rust-type-util.h

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 09bbe450bd5..06f64a01dce 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -134,6 +134,7 @@ GRS_OBJS = \
 rust/rust-hir-type-check-implitem.o \
 rust/rust-hir-dot-operator.o \
 rust/rust-hir-path-probe.o \
+rust/rust-type-util.o \
 rust/rust-coercion.o \
 rust/rust-casts.o \
 rust/rust-unify.o \
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc 
b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index 6e42b7b7b23..e302e27f4ab 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -483,78 +483,5 @@ TypeCheckBase::resolve_generic_params (
 }
 }
 
-bool
-TypeCheckBase::query_type (HirId reference, TyTy::BaseType **result)
-{
-  if (context->query_in_progress (reference))
-return false;
-
-  if (context->lookup_type (reference, result))
-return true;
-
-  context->insert_query (reference);
-
-  HIR::Item *item = mappings->lookup_hir_item (reference);
-  if (item != nullptr)
-{
-  rust_debug_loc (item->get_locus (), "resolved item {%u} to", reference);
-  *result = TypeCheckItem::Resolve (*item);
-  context->query_completed (reference);
-  return true;
-}
-
-  HirId parent_impl_id = UNKNOWN_HIRID;
-  HIR::ImplItem *impl_item
-= mappings->lookup_hir_implitem (reference, &parent_impl_id);
-  if (impl_item != nullptr)
-{
-  HIR::ImplBlock *impl_block
-   = mappings->lookup_hir_impl_block (parent_impl_id);
-  rust_assert (impl_block != nullptr);
-
-  // found an impl item
-  rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to",
- reference);
-
-  *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item);
-  context->query_completed (reference);
-  return true;
-}
-
-  // is it an impl_type?
-  HIR::ImplBlock *impl_block_by_type = nullptr;
-  bool found_impl_block_type
-= mappings->lookup_impl_block_type (reference, &impl_block_by_type);
-  if (found_impl_block_type)
-{
-  *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type);
-  context->query_completed (reference);
-  return true;
-}
-
-  // is it an extern item?
-  HirId parent_extern_block_id = UNKNOWN_HIRID;
-  HIR::ExternalItem *extern_item
-= mappings->lookup_hir_extern_item (reference, &parent_extern_block_id);
-  if (extern_item != nullptr)
-{
-  HIR::ExternBlock *block
-   = mappings->lookup_hir_extern_block (parent_extern_block_id);
-  rust_assert (block != nullptr);
-
-  *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block);
-  context->query_completed (reference);
-  return true;
-}
-
-  // more?
-  Location possible_locus = mappings->lookup_location (reference);
-  rust_debug_loc (possible_locus, "query system failed to resolve: [%u]",
- reference);
-  context->query_completed (reference);
-
-  return false;
-}
-
 } // namespace Resolver
 } // namespace Rust
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h 
b/gcc/rust/typecheck/rust-hir-type-check-base.h
index 335014339f3..b8ff2cf6dc9 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.h
@@ -69,8 +69,6 @@ protected:
 const std::vector> &generic_params,
 std::vector &substitutions);
 
-  bool query_type (HirId reference, TyTy::BaseType **result);
-
   Analysis::Mappings *mappings;
   Resolver *resolver;
   TypeCheckContext *context;
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h 
b/gcc/rust/typecheck/rust-hir-type-check.h
index 512453947a6..6d4b9b8a62f 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -19,6 +19,7 @@
 #ifndef RUST_HIR_TYPE_CHECK
 #define RUST_HIR_TYPE_CHECK
 
+#include "rust-type-util.h"
 #include "rust-hir-full-decls.h"
 #include "rust-hir-map.h"
 #include "rust-tyty.h"
diff --git a/gcc/rust/typecheck/rus

[committed 77/88] gccrs: Add trailing newline

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.h: Add trailing newline before EOF.

Signed-off-by: Owen Avery 
---
 gcc/rust/checks/errors/rust-feature-gate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/rust/checks/errors/rust-feature-gate.h 
b/gcc/rust/checks/errors/rust-feature-gate.h
index 6768c4c2498..05789cf4751 100644
--- a/gcc/rust/checks/errors/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/rust-feature-gate.h
@@ -193,4 +193,4 @@ private:
   std::set valid_features;
 };
 } // namespace Rust
-#endif
\ No newline at end of file
+#endif
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 75/88] gccrs: Support for Sized builtin marker trait

2023-04-05 Thread arthur . cohen
From: Philip Herron 

When implementing general bounds checking as part of unify calls, we did
not check associated types on bounds which lead to alot of missed error
checking. This now recursively checks the bounds and the associated types
with a decent error message. This also required us to implement the Sized
marker trait to keep existing test-cases happy.

Fixes #1725

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.cc 
(TraitReference::clear_associated_types): make const
(TraitReference::clear_associated_type_projections): new interface
* typecheck/rust-hir-trait-reference.h:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): 
refactor
(TraitItemReference::associated_type_reset): reset projections
* typecheck/rust-hir-type-bounds.h:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix 
bounds
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): 
refactor into cc file
(TypeBoundsProbe::Probe): refactor
(TypeBoundsProbe::is_bound_satisfied_for_type): likewise
(TypeBoundsProbe::assemble_sized_builtin): add builtin for Sized
(TypeCheckBase::get_predicate_from_bound): refactor
(TypeBoundPredicate::lookup_associated_type): refactor
* typecheck/rust-tyty-subst.cc (SubstitutionRef::lookup_associated_impl)
(SubstitutionRef::prepare_higher_ranked_bounds): new interface to clear 
hanging bounds
(SubstitutionRef::monomorphize): refactor
* typecheck/rust-tyty-subst.h:
* typecheck/rust-tyty.cc (BaseType::get_locus): helper
(BaseType::satisfies_bound): ensure bounds are satisfied and assoicated 
types
(ParamType::ParamType): new field in constructor
(ParamType::clone): update clone
(ParamType::set_implicit_self_trait): new interface
(ParamType::is_implicit_self_trait): likewise
* typecheck/rust-tyty.h: cleanup
* util/rust-hir-map.cc (Mappings::Mappings): builtin marker
(Mappings::~Mappings): delete marker
(Mappings::lookup_builtin_marker): lookup
* util/rust-hir-map.h: update header

gcc/testsuite/ChangeLog:

* rust/compile/issue-1725-1.rs: New test.
* rust/compile/issue-1725-2.rs: New test.
---
 .../typecheck/rust-hir-trait-reference.cc |  18 +-
 gcc/rust/typecheck/rust-hir-trait-reference.h |   6 +-
 gcc/rust/typecheck/rust-hir-trait-resolve.cc  |  27 +-
 gcc/rust/typecheck/rust-hir-type-bounds.h |  34 +-
 .../typecheck/rust-hir-type-check-expr.cc |   6 +
 gcc/rust/typecheck/rust-tyty-bounds.cc| 111 ++-
 gcc/rust/typecheck/rust-tyty-subst.cc | 291 ++
 gcc/rust/typecheck/rust-tyty-subst.h  |  12 +-
 gcc/rust/typecheck/rust-tyty.cc   |  82 -
 gcc/rust/typecheck/rust-tyty.h|   8 +-
 gcc/rust/util/rust-hir-map.cc |  17 +-
 gcc/rust/util/rust-hir-map.h  |   3 +
 gcc/testsuite/rust/compile/issue-1725-1.rs|  19 ++
 gcc/testsuite/rust/compile/issue-1725-2.rs|  28 ++
 14 files changed, 476 insertions(+), 186 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-1725-1.rs
 create mode 100644 gcc/testsuite/rust/compile/issue-1725-2.rs

diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.cc 
b/gcc/rust/typecheck/rust-hir-trait-reference.cc
index 8574988fb0b..a1229adc06c 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.cc
@@ -343,14 +343,26 @@ TraitReference::on_resolved ()
 }
 
 void
-TraitReference::clear_associated_types ()
+TraitReference::clear_associated_types () const
 {
-  for (auto &item : item_refs)
+  for (const auto &item : item_refs)
+{
+  bool is_assoc_type = item.get_trait_item_type ()
+  == TraitItemReference::TraitItemType::TYPE;
+  if (is_assoc_type)
+   item.associated_type_reset (false);
+}
+}
+
+void
+TraitReference::clear_associated_type_projections () const
+{
+  for (const auto &item : item_refs)
 {
   bool is_assoc_type = item.get_trait_item_type ()
   == TraitItemReference::TraitItemType::TYPE;
   if (is_assoc_type)
-   item.associated_type_reset ();
+   item.associated_type_reset (true);
 }
 }
 
diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h 
b/gcc/rust/typecheck/rust-hir-trait-reference.h
index f3703efcced..d20b2952e5b 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -106,7 +106,7 @@ public:
 
   void associated_type_set (TyTy::BaseType *ty) const;
 
-  void associated_type_reset () const;
+  void associated_type_reset (bool only_projections) const;
 
   bool is_object_safe () const;
 
@@ -212,7 +212,9 @@ public:
 
   void on_resolved ();
 
-  void clear_associated_types ();
+  void clear_associated_types (

[committed 80/88] gccrs: Add AST::AltPattern class

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc
(Dump::visit): Add AltPattern visitor.
* ast/rust-ast-dump.h:
(Dump::visit): Add AltPattern visitor.
* ast/rust-ast-full-decls.h
(class AltPattern): Add declaration.
* ast/rust-ast-visitor.h:
(ASTVisitor::visit): Add AltPattern visitor.
* ast/rust-ast.cc
(AltPattern::as_string): Add definition.
(AltPattern::accept_vis): Add definition.
* ast/rust-pattern.h
(class AltPattern): Add declaration.
* checks/errors/rust-feature-gate.h:
(FeatureGate::visit) Add AltPattern visitor
* expand/rust-attribute-visitor.cc
(AttrVisitor::visit): Add AltPattern visitor.
* expand/rust-attribute-visitor.h:
(AttrVisitor::visit): Add AltPattern visitor.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Add AltPattern visitor.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Add AltPattern visitor.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Add AltPattern visitor.
* resolve/rust-ast-resolve-base.h:
(ResolverBase::visit): Add AltPattern visitor.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Add AltPattern visitor.
* resolve/rust-early-name-resolver.h:
(EarlyNameResolver::visit): Add AltPattern visitor.
* util/rust-attributes.cc
(AttributeChecker::visit): Add AltPattern visitor.
* util/rust-attributes.h:
(AttributeChecker::visit): Add AltPattern visitor.

Signed-off-by: Owen Avery 
---
 gcc/rust/ast/rust-ast-dump.cc|  4 ++
 gcc/rust/ast/rust-ast-dump.h |  1 +
 gcc/rust/ast/rust-ast-full-decls.h   |  1 +
 gcc/rust/ast/rust-ast-visitor.h  |  1 +
 gcc/rust/ast/rust-ast.cc | 17 +
 gcc/rust/ast/rust-pattern.h  | 66 
 gcc/rust/checks/errors/rust-feature-gate.h   |  1 +
 gcc/rust/expand/rust-attribute-visitor.cc| 14 +
 gcc/rust/expand/rust-attribute-visitor.h |  1 +
 gcc/rust/hir/rust-ast-lower-base.cc  |  3 +
 gcc/rust/hir/rust-ast-lower-base.h   |  1 +
 gcc/rust/resolve/rust-ast-resolve-base.cc|  4 ++
 gcc/rust/resolve/rust-ast-resolve-base.h |  1 +
 gcc/rust/resolve/rust-early-name-resolver.cc |  7 +++
 gcc/rust/resolve/rust-early-name-resolver.h  |  1 +
 gcc/rust/util/rust-attributes.cc |  4 ++
 gcc/rust/util/rust-attributes.h  |  1 +
 17 files changed, 128 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 58eb35ad1db..10fb313c2c7 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -1678,6 +1678,10 @@ void
 Dump::visit (SlicePattern &)
 {}
 
+void
+Dump::visit (AltPattern &)
+{}
+
 // rust-stmt.h
 void
 Dump::visit (EmptyStmt &)
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index 56918f5fc98..dfe6db0dd96 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -293,6 +293,7 @@ private:
   void visit (TuplePattern &pattern);
   void visit (GroupedPattern &pattern);
   void visit (SlicePattern &pattern);
+  void visit (AltPattern &pattern);
 
   // rust-stmt.h
   void visit (EmptyStmt &stmt);
diff --git a/gcc/rust/ast/rust-ast-full-decls.h 
b/gcc/rust/ast/rust-ast-full-decls.h
index 58b12a1be0e..9d7b00ac5a2 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -249,6 +249,7 @@ class TuplePatternItemsRanged;
 class TuplePattern;
 class GroupedPattern;
 class SlicePattern;
+class AltPattern;
 
 // rust-type.h
 class TraitBound;
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index aa59a115ee6..1083e834770 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -203,6 +203,7 @@ public:
   virtual void visit (TuplePattern &pattern) = 0;
   virtual void visit (GroupedPattern &pattern) = 0;
   virtual void visit (SlicePattern &pattern) = 0;
+  virtual void visit (AltPattern &pattern) = 0;
 
   // rust-stmt.h
   virtual void visit (EmptyStmt &stmt) = 0;
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 972cba2e7bb..07983b7da06 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -2704,6 +2704,17 @@ SlicePattern::as_string () const
   return str;
 }
 
+std::string
+AltPattern::as_string () const
+{
+  std::string str ("AltPattern: ");
+
+  for (const auto &pattern : alts)
+str += "\n " + pattern->as_string ();
+
+  return str;
+}
+
 std::string
 TuplePatternItemsMultiple::as_string () const
 {
@@ -5649,6 +5660,12 @@ SlicePattern::accept_vis (ASTVisitor &vis)
   vis.visit (*this);
 }
 
+void
+AltPattern::accept_vis (ASTVisitor &vis)
+{
+  vis.visit (*this);
+}
+
 void
 EmptyStmt::accept_vis (ASTVisitor &vis)
 {
diff --git a/gcc/rus

[committed 83/88] gccrs: add test case to show our query-type system is working

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Fixes #1361

Signed-off-by: Philip Herron 

gcc/testsuite/ChangeLog:

* rust/compile/issue-1361.rs: New test.
---
 gcc/testsuite/rust/compile/issue-1361.rs | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-1361.rs

diff --git a/gcc/testsuite/rust/compile/issue-1361.rs 
b/gcc/testsuite/rust/compile/issue-1361.rs
new file mode 100644
index 000..f8909727216
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1361.rs
@@ -0,0 +1,8 @@
+// { dg-options "-w" }
+fn foo() -> S {
+S { a: 15 }
+}
+
+struct S {
+a: i32,
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 85/88] gccrs: diagnostic: Refactor Error class

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

The class now allows for more variants including a `Hint` one which
then gets emitted by calling `rust_inform`. This allows us to display
hints/tips/notes in backtracking contexts such as the parser.

gcc/rust/ChangeLog:

* rust-diagnostics.h (struct Error): Add new Kind enum and various new
static constructors to allow for hints as well.
* rust-diagnostics.cc (Error::Error): Use new `kind` field properly.
* checks/errors/privacy/rust-visibility-resolver.cc
(VisibilityResolver::resolve_module_path): Use new Error API.
* expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): 
Likewise.
* expand/rust-macro-expand.cc (parse_many): Likewise.
(transcribe_type): Likewise.
* parse/rust-parse-impl.h (Parser::parse_crate): Likewise.
* rust-session-manager.cc (Session::handle_crate_name): Likewise.
* ast/rust-ast.cc (Module::load_items): Likewise.
---
 gcc/rust/ast/rust-ast.cc  |  2 +-
 .../privacy/rust-visibility-resolver.cc   |  4 +-
 gcc/rust/expand/rust-macro-builtins.cc|  2 +-
 gcc/rust/expand/rust-macro-expand.cc  |  4 +-
 gcc/rust/parse/rust-parse-impl.h  |  2 +-
 gcc/rust/rust-diagnostics.cc  | 43 --
 gcc/rust/rust-diagnostics.h   | 56 ---
 gcc/rust/rust-session-manager.cc  |  6 +-
 8 files changed, 98 insertions(+), 21 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 07983b7da06..68a7dfdc662 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4084,7 +4084,7 @@ Module::load_items ()
   inner_attrs = parser.parse_inner_attributes ();
   auto parsed_items = parser.parse_items ();
   for (const auto &error : parser.get_errors ())
-error.emit_error ();
+error.emit ();
 
   items = std::move (parsed_items);
   kind = ModuleKind::LOADED;
diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc 
b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
index becb9fd93a7..30afaf9174e 100644
--- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
+++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
@@ -63,7 +63,7 @@ VisibilityResolver::resolve_module_path (const 
HIR::SimplePath &restriction,
   NodeId ref_node_id = UNKNOWN_NODEID;
   if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
 {
-  invalid_path.emit_error ();
+  invalid_path.emit ();
   return false;
 }
   // FIXME: Add a hint here if we can find the path in another scope, such as
@@ -77,7 +77,7 @@ VisibilityResolver::resolve_module_path (const 
HIR::SimplePath &restriction,
   auto module = mappings.lookup_module (ref);
   if (!module)
 {
-  invalid_path.emit_error ();
+  invalid_path.emit ();
   return false;
 }
 
diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index 97594921dec..cf90b384cb5 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -736,7 +736,7 @@ MacroBuiltin::include_handler (Location invoc_locus, 
AST::MacroInvocData &invoc)
   bool has_error = !parser.get_errors ().empty ();
 
   for (const auto &error : parser.get_errors ())
-error.emit_error ();
+error.emit ();
 
   if (has_error)
 {
diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index 4b494490424..71aafef85b0 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -848,7 +848,7 @@ parse_many (Parser &parser, TokenId 
&delimiter,
   if (node.is_error ())
{
  for (auto err : parser.get_errors ())
-   err.emit_error ();
+   err.emit ();
 
  return AST::Fragment::create_error ();
}
@@ -991,7 +991,7 @@ transcribe_type (Parser &parser)
 
   auto type = parser.parse_type (true);
   for (auto err : parser.get_errors ())
-err.emit_error ();
+err.emit ();
 
   auto end = lexer.get_offs ();
 
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index cc5436cff63..6a98bcce654 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -444,7 +444,7 @@ Parser::parse_crate ()
 
   // emit all errors
   for (const auto &error : error_table)
-error.emit_error ();
+error.emit ();
 
   return std::unique_ptr (
 new AST::Crate (std::move (items), std::move (inner_attrs)));
diff --git a/gcc/rust/rust-diagnostics.cc b/gcc/rust/rust-diagnostics.cc
index c0f02c2831e..4e5c2ececd4 100644
--- a/gcc/rust/rust-diagnostics.cc
+++ b/gcc/rust/rust-diagnostics.cc
@@ -231,14 +231,49 @@ rust_debug_loc (const Location location, const char *fmt, 
...)
 }
 
 namespace Rust {
-Error::Error (const Location location, const char *fmt, ...) : locus (location)
+
+/**
+ * This function takes ownership of `args` and calls `va_end`

[committed 88/88] gccrs: Fix issue with parsing unsafe block expression statements

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_stmt): Handle unsafe expression statements.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1422.rs: New test.

Signed-off-by: Owen Avery 
---
 gcc/rust/parse/rust-parse-impl.h | 10 +-
 gcc/testsuite/rust/compile/issue-1422.rs |  7 +++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-1422.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 1e5b2dc85ed..db32803ddbe 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6131,7 +6131,15 @@ Parser::parse_stmt 
(ParseRestrictions restrictions)
   /* if any of these (should be all possible VisItem prefixes), parse a
* VisItem can't parse item because would require reparsing outer
* attributes */
-  return parse_vis_item (std::move (outer_attrs));
+  // may also be unsafe block
+  if (lexer.peek_token (1)->get_id () == LEFT_CURLY)
+   {
+ return parse_expr_stmt (std::move (outer_attrs), restrictions);
+   }
+  else
+   {
+ return parse_vis_item (std::move (outer_attrs));
+   }
   break;
 case SUPER:
 case SELF:
diff --git a/gcc/testsuite/rust/compile/issue-1422.rs 
b/gcc/testsuite/rust/compile/issue-1422.rs
new file mode 100644
index 000..b178cda185e
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1422.rs
@@ -0,0 +1,7 @@
+macro_rules! test {
+() => { unsafe {} };
+}
+
+fn main() {
+test!();
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 76/88] gccrs: Fix regression in testcase

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Fixes #776

Signed-off-by: Philip Herron 

gcc/testsuite/ChangeLog:

* rust/compile/torture/traits10.rs: Fix test-case
---
 .../rust/compile/torture/traits10.rs  | 64 ++-
 1 file changed, 62 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/rust/compile/torture/traits10.rs 
b/gcc/testsuite/rust/compile/torture/traits10.rs
index a02927007b3..4cf36e3c6f1 100644
--- a/gcc/testsuite/rust/compile/torture/traits10.rs
+++ b/gcc/testsuite/rust/compile/torture/traits10.rs
@@ -1,5 +1,65 @@
-trait Foo // where
-// Self: Sized,
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "clone"]
+pub trait Clone: Sized {
+fn clone(&self) -> Self;
+
+fn clone_from(&mut self, source: &Self) {
+*self = source.clone()
+}
+}
+
+mod impls {
+use super::Clone;
+
+macro_rules! impl_clone {
+($($t:ty)*) => {
+$(
+impl Clone for $t {
+fn clone(&self) -> Self {
+*self
+}
+}
+)*
+}
+}
+
+impl_clone! {
+usize u8 u16 u32 u64 // u128
+isize i8 i16 i32 i64 // i128
+f32 f64
+bool char
+}
+}
+
+#[lang = "copy"]
+pub trait Copy: Clone {
+// Empty.
+}
+
+mod copy_impls {
+use super::Copy;
+
+macro_rules! impl_copy {
+($($t:ty)*) => {
+$(
+impl Copy for $t {}
+)*
+}
+}
+
+impl_copy! {
+usize u8 u16 u32 u64 // u128
+isize i8 i16 i32 i64 // i128
+f32 f64
+bool char
+}
+}
+
+trait Foo
+where
+Self: Sized,
 {
 fn get(self) -> i32;
 
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 67/88] gccrs: Add test

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/testsuite/ChangeLog:

* rust/compile/variadic.rs: New test.

Signed-off-by: Owen Avery 
---
 gcc/testsuite/rust/compile/variadic.rs | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/variadic.rs

diff --git a/gcc/testsuite/rust/compile/variadic.rs 
b/gcc/testsuite/rust/compile/variadic.rs
new file mode 100644
index 000..886341b088c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/variadic.rs
@@ -0,0 +1,8 @@
+extern "C" {
+fn printf(s: *const i8, ...);
+}
+
+fn main() {
+// { dg-error "expected .c_int. variadic argument" "" { target *-*-* } .+1 
}
+printf("%d\n" as *const str as *const i8, 1i8);
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 70/88] gccrs: testsuite: Add empty string macro test

2023-04-05 Thread arthur . cohen
From: Pierre-Emmanuel Patry 

Add two new tests with empty string for include_str and include_bytes
macros.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1830_bytes.rs: New test.
* rust/compile/issue-1830_str.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry 
---
 gcc/testsuite/rust/compile/issue-1830_bytes.rs | 8 
 gcc/testsuite/rust/compile/issue-1830_str.rs   | 8 
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/issue-1830_bytes.rs
 create mode 100644 gcc/testsuite/rust/compile/issue-1830_str.rs

diff --git a/gcc/testsuite/rust/compile/issue-1830_bytes.rs 
b/gcc/testsuite/rust/compile/issue-1830_bytes.rs
new file mode 100644
index 000..dcc53b73b19
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1830_bytes.rs
@@ -0,0 +1,8 @@
+#[rustc_builtin_macro]
+macro_rules! include_bytes {
+() => {{}};
+}
+
+fn main() {
+include_bytes!(""); // { dg-excess-errors "Is a directory" }
+}
diff --git a/gcc/testsuite/rust/compile/issue-1830_str.rs 
b/gcc/testsuite/rust/compile/issue-1830_str.rs
new file mode 100644
index 000..6cf835ba9bd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1830_str.rs
@@ -0,0 +1,8 @@
+#[rustc_builtin_macro]
+macro_rules! include_str {
+() => {{}};
+}
+
+fn main() {
+include_str!(""); // { dg-excess-errors "Is a directory" }
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 60/88] gccrs: macros: Perform macro expansion in a fixed-point fashion.

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

This commit changes our macro expansion system from an eager and recursive
macro expansion to a fixed-point like system. Instead of, when seeing
a macro invocation, expanding it and all of the macros within it, we
now perform multiple passes of expansion on the entire crate.

This, however, leads to a problem. Rust macros are expanded lazily, but
Rust builtin macros should be expanded eagerly. Due to this, we must
work around the lazy expansion in builtin macros and perform eager
expansion for each pass of the fixed-point, before finally expanding
the builtin when there are no longer any inner macro invocations.

To perform proper macro scoping, the ENR now keeps track of the current
scope (`current_scope` member) and resolves macros accordingly.

This is done through the use of the `scoped` method, which creates a new
scope, runs a specified lambda and then exits the scope. This prevents
pushing/popping errors that we've seen happen already in similar
contexts.

We might think about generalizing it to other classes, providing a
`Scoped` class or similar

gcc/rust/ChangeLog:

* ast/rust-macro.cc: New file.
* Make-lang.in: Add `rust-macro.o` object
* ast/rust-ast-fragment.cc (Fragment::Fragment): Change API around
the construction of AST fragments.
(Fragment::operator=): Correct `Fragment::operator=` to take into
account the fragment tokens.
(Fragment::create_error): Use new constructor.
(Fragment::complete): Remove in favor of new constructor.
(Fragment::unexpanded): Remove as that Fragment type is no longer used
or possible.
(Fragment::get_tokens): Add helper to access a fragment's tokens.
* ast/rust-ast-fragment.h (enum class): Remove `FragmentKind::Unused`
* ast/rust-ast.cc (MacroInvocation::as_string): Display
builtin macro invocations properly.
* ast/rust-ast.h: Fix `DelimTokenTree` class copy constructors and
handling of its token vector.
* ast/rust-macro.h (class MacroMatcher): Format.
(class MetaItemSeq): Likewise.
(builtin_macro_from_string): Get a `BuiltinMacroKind` from a given
string, i.e the name of the macro (`assert!`, `cfg!` and so on).
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Do not expand
macros recursively anymore.
(AttrVisitor::maybe_expand_expr): Likewise.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-attribute-visitor.h: Likewise, and remove
`expand_macro_fragment_recursively` function.
* expand/rust-macro-builtins.cc (make_token): Add shorthand for
returning `std::unique_ptr`s.
(make_macro_invocation): Add shorthand for returning fragments
containing builtin macro invocations.
(try_expand_macro_expression): Do not expand macros recursively.
(try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Error out more appropriately.
(MacroBuiltin::compile_error_handler): Add explanation for eager
invocation
(MacroBuiltin::file_handler): Return the proper tokens associated with
macro invocation, and builtin macros in the case of necessary eager
expansion.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add function to expand eager invocations *once* in the fixed point
pipeline.
(MacroExpander::expand_invoc): Call into `expand_eager_invocations` for
builtin macro invocations.
(MacroExpander::expand_crate): Use new `AttrVisitor` API.
(parse_many): Return tokens in `AST::Fragment`.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Add `has_changed`
flag for fixed point checking.
* resolve/rust-early-name-resolver.cc 
(EarlyNameResolver::EarlyNameResolver):
Keep track of the current macro scope.
(EarlyNameResolver::go): Use `scoped` API.
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h: Add `scoped` API.
* rust-session-manager.cc (Session::expansion): Perform macro expansion
in a fixed-point fashion.

gcc/testsuite/ChangeLog:

* rust/compile/macro17.rs: Fix testsuite for new recursion errors.
* rust/compile/macro44.rs: Fix invalid testcase assertions.
* rust/compile/builtin_macro_recurse.rs: Fix invalid test.
 

[committed 71/88] gccrs: Add support for parsing empty tuple patterns.

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_grouped_or_tuple_pattern): Add support for empty tuple 
patterns.

gcc/testsuite/ChangeLog:

* rust/compile/parse_empty_tuple_pattern.rs: New test.

Signed-off-by: Owen Avery 
---
 gcc/rust/parse/rust-parse-impl.h| 9 +
 gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs | 3 +++
 2 files changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 4ceb978f7f4..cc5436cff63 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -10926,6 +10926,15 @@ 
Parser::parse_grouped_or_tuple_pattern ()
   return std::unique_ptr (
new AST::TuplePattern (std::move (items), paren_locus));
 }
+  else if (lexer.peek_token ()->get_id () == RIGHT_PAREN)
+{
+  skip_token (RIGHT_PAREN);
+  auto items = std::unique_ptr (
+   new AST::TuplePatternItemsMultiple (
+ std::vector> ()));
+  return std::unique_ptr (
+   new AST::TuplePattern (std::move (items), paren_locus));
+}
 
   // parse initial pattern (required)
   std::unique_ptr initial_pattern = parse_pattern ();
diff --git a/gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs 
b/gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs
new file mode 100644
index 000..d974d31b8ba
--- /dev/null
+++ b/gcc/testsuite/rust/compile/parse_empty_tuple_pattern.rs
@@ -0,0 +1,3 @@
+fn main() {
+let () = ();
+}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 74/88] gccrs: Add new virtual function HIR::ImplItem::get_impl_item_name

2023-04-05 Thread arthur . cohen
From: Philip Herron 

Signed-off-by: Philip Herron 

gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h: implement virtual function
* hir/tree/rust-hir.h: add virtual function
---
 gcc/rust/hir/tree/rust-hir-item.h | 17 -
 gcc/rust/hir/tree/rust-hir.h  |  2 ++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/hir/tree/rust-hir-item.h 
b/gcc/rust/hir/tree/rust-hir-item.h
index f7bf1f879c8..03e1f71abb5 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -1226,6 +1226,11 @@ public:
 
   SelfParam &get_self_param () { return self; }
 
+  std::string get_impl_item_name () const override final
+  {
+return get_function_name ();
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object
* rather than base */
@@ -1345,6 +1350,11 @@ public:
 return get_mappings ();
   };
 
+  std::string get_impl_item_name () const override final
+  {
+return get_new_type_name ();
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object
* rather than base */
@@ -2116,7 +2126,7 @@ public:
 
   Expr *get_expr () { return const_expr.get (); }
 
-  std::string get_identifier () { return identifier; }
+  std::string get_identifier () const { return identifier; }
 
   Analysis::NodeMapping get_impl_mappings () const override
   {
@@ -2130,6 +2140,11 @@ public:
 
   ItemKind get_item_kind () const override { return ItemKind::Constant; }
 
+  std::string get_impl_item_name () const override final
+  {
+return get_identifier ();
+  }
+
 protected:
   /* Use covariance to implement clone function as returning this object
* rather than base */
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 314aafb32d3..28f1f21a6bb 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -839,6 +839,8 @@ public:
 
   virtual ImplItemType get_impl_item_type () const = 0;
 
+  virtual std::string get_impl_item_name () const = 0;
+
 protected:
   // Clone function implementation as pure virtual method
   virtual ImplItem *clone_inherent_impl_item_impl () const = 0;
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 78/88] gccrs: builtins: Return empty list of tokens instead of nullptr

2023-04-05 Thread arthur . cohen
From: Arthur Cohen 

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Do not
return nullptr token in expansion of `include!()`

gcc/testsuite/ChangeLog:

* rust/compile/empty.in: New test.
* rust/compile/include_empty.rs: New test.
---
 gcc/rust/expand/rust-macro-builtins.cc  | 15 +--
 gcc/testsuite/rust/compile/empty.in |  1 +
 gcc/testsuite/rust/compile/include_empty.rs |  8 
 3 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/empty.in
 create mode 100644 gcc/testsuite/rust/compile/include_empty.rs

diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index 3b6f69bbd69..97594921dec 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -752,8 +752,19 @@ MacroBuiltin::include_handler (Location invoc_locus, 
AST::MacroInvocData &invoc)
   nodes.push_back (node);
 }
 
-  // FIXME: Do not return an empty token vector here
-  return AST::Fragment (nodes, nullptr);
+  // FIXME: This returns an empty vector of tokens and works fine, but is that
+  // the expected behavior? `include` macros are a bit harder to reason about
+  // since they include tokens. Furthermore, our lexer has no easy way to 
return
+  // a slice of tokens like the MacroInvocLexer. So it gets even harder to
+  // extrac tokens from here. For now, let's keep it that way and see if it
+  // eventually breaks, but I don't expect it to cause many issues since the
+  // list of tokens is only used when a macro invocation mixes eager
+  // macro invocations and already expanded tokens. Think
+  // `concat!(a!(), 15, b!())`. We need to be able to expand a!(), expand b!(),
+  // and then insert the `15` token in between. In the case of `include!()`, we
+  // only have one argument. So it's either going to be a macro invocation or a
+  // string literal.
+  return AST::Fragment (nodes, std::vector> ());
 }
 
 AST::Fragment
diff --git a/gcc/testsuite/rust/compile/empty.in 
b/gcc/testsuite/rust/compile/empty.in
new file mode 100644
index 000..8b137891791
--- /dev/null
+++ b/gcc/testsuite/rust/compile/empty.in
@@ -0,0 +1 @@
+
diff --git a/gcc/testsuite/rust/compile/include_empty.rs 
b/gcc/testsuite/rust/compile/include_empty.rs
new file mode 100644
index 000..28e940fa0ac
--- /dev/null
+++ b/gcc/testsuite/rust/compile/include_empty.rs
@@ -0,0 +1,8 @@
+#[rustc_builtin_macro]
+macro_rules! include {
+() => {};
+}
+
+include!("empty.in");
+
+fn main() {}
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 72/88] gccrs: Implemented UTF-8 checking for include_str!()

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc
(MacroBuiltin::include_str_handler): Add check for valid UTF-8.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_include_str.rs:
Include test of invalid UTF-8.
* rust/compile/invalid_utf8: File with invalid UTF-8.

Signed-off-by: Owen Avery 
---
 gcc/rust/expand/rust-macro-builtins.cc| 51 ++-
 .../rust/compile/builtin_macro_include_str.rs |  1 +
 gcc/testsuite/rust/compile/invalid_utf8   |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/invalid_utf8

diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index e594a2500d0..3b6f69bbd69 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -389,8 +389,55 @@ MacroBuiltin::include_str_handler (Location invoc_locus,
 
   std::vector bytes = load_file_bytes (target_filename.c_str ());
 
-  /* FIXME: Enforce that the file contents are valid UTF-8.  */
-  std::string str ((const char *) &bytes[0], bytes.size ());
+  /* FIXME: reuse lexer */
+  int expect_single = 0;
+  for (uint8_t b : bytes)
+{
+  if (expect_single)
+   {
+ if ((b & 0xC0) != 0x80)
+   /* character was truncated, exit with expect_single != 0 */
+   break;
+ expect_single--;
+   }
+  else if (b & 0x80)
+   {
+ if (b >= 0xF8)
+   {
+ /* more than 4 leading 1s */
+ expect_single = 1;
+ break;
+   }
+ else if (b >= 0xF0)
+   {
+ /* 4 leading 1s */
+ expect_single = 3;
+   }
+ else if (b >= 0xE0)
+   {
+ /* 3 leading 1s */
+ expect_single = 2;
+   }
+ else if (b >= 0xC0)
+   {
+ /* 2 leading 1s */
+ expect_single = 1;
+   }
+ else
+   {
+ /* only 1 leading 1 */
+ expect_single = 1;
+ break;
+   }
+   }
+}
+
+  std::string str;
+  if (expect_single)
+rust_error_at (invoc_locus, "%s was not a valid utf-8 file",
+  target_filename.c_str ());
+  else
+str = std::string ((const char *) &bytes[0], bytes.size ());
 
   auto node = AST::SingleASTNode (make_string (invoc_locus, str));
   auto str_tok = make_token (Token::make_string (invoc_locus, std::move 
(str)));
diff --git a/gcc/testsuite/rust/compile/builtin_macro_include_str.rs 
b/gcc/testsuite/rust/compile/builtin_macro_include_str.rs
index 38f5e3b7334..8092193195d 100644
--- a/gcc/testsuite/rust/compile/builtin_macro_include_str.rs
+++ b/gcc/testsuite/rust/compile/builtin_macro_include_str.rs
@@ -10,4 +10,5 @@ fn main () {
   include_str! ("foo.txt", "bar.txt"); // { dg-error "macro takes 1 argument" 
"" }
   include_str! ("builtin_macro_include_str.rs"); // ok
   include_str! ("builtin_macro_include_str.rs",); // trailing comma ok
+  include_str! ("invalid_utf8"); // { dg-error "invalid_utf8 was not a valid 
utf-8 file" "" }
 }
diff --git a/gcc/testsuite/rust/compile/invalid_utf8 
b/gcc/testsuite/rust/compile/invalid_utf8
new file mode 100644
index 000..29e181ebb88
--- /dev/null
+++ b/gcc/testsuite/rust/compile/invalid_utf8
@@ -0,0 +1 @@
+�
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[committed 87/88] gccrs: Address unsafe with/without block handling ambiguity

2023-04-05 Thread arthur . cohen
From: Owen Avery 

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_expr_stmt): Remove hypothetical unsafe + 
expr_stmt_without_block handling.

Signed-off-by: Owen Avery 
---
 gcc/rust/parse/rust-parse-impl.h | 15 +++
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 6a98bcce654..1e5b2dc85ed 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -7188,18 +7188,9 @@ Parser::parse_expr_stmt 
(AST::AttrVec outer_attrs,
  }
   }
   case UNSAFE: {
-   /* FIXME: are there any expressions without blocks that can have
-* unsafe as their first token? Or is unsafe the only one? */
-   // safe side for now
-   if (lexer.peek_token (1)->get_id () == LEFT_CURLY)
- {
-   return parse_expr_stmt_with_block (std::move (outer_attrs));
- }
-   else
- {
-   return parse_expr_stmt_without_block (std::move (outer_attrs),
- restrictions);
- }
+   // unsafe block
+   // https://doc.rust-lang.org/reference/unsafe-keyword.html
+   return parse_expr_stmt_with_block (std::move (outer_attrs));
   }
 default:
   // not a parse expr with block, so must be expr without block
-- 
2.40.0

-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust


[GSoC] gcc-rs - Unicode Support or Metadata

2023-04-05 Thread Charlie Hernandez via Gcc-rust
Dear GCC members,

I understand that I am late in submitting this proposal. However, I found
out about gcc-rust and Google of Code three hours ago, and instead of doing
nothing, I decided that it is in my best interest to apply nonetheless. I'm
interested in Rust and the GCC frontend for many reasons, and I would like
to be considered for this involvement. I can be fully committed to the
project if any of my proposals are accepted.


# General Information
Name: Carlos "Charlie Cruz" Hernandez
Email: cj...@rice.edu
University: Rice University '2026
Major/Focus: Mathematics and Linguistics
Country/Timezone: United States / Eastern Standard Time
What is your Open Source Experience so far?

Online I go by "SeniorMars," (https://github.com/SeniorMars), and I have
contributed to the following significant projects: Rust-analyzer, Neovim,
Coc-rust-analyzer, and the Rust compiler for documentation. I'm highly
active in the Neovim, Latex community and working on several Neovim plugins
for the Typst markup language. Additionally, at Rice, I taught.
https://lazy.rice.edu/ (website is outdated due to University policies --
for now) that aims to teach open source concepts to students. Finally, I
have a youtube channel dedicated to open-source concepts:
https://www.youtube.com/@SeniorMarsTries. For the sake of this project, I
have taken my University's programming class as a Freshman. Also, notably,
I'm working on a tree-sitter parser for the Typst markup language that
deals with Unicode. In Neovim, I'm also trying to tackle "concealed text"
with virtual text. Although I have yet to work with gcc-rs, I'm confident I
can help.

# Project Information

I wish to tackle one of the three projects suggested in the gcc-rust
section: Unicode support, Metadata, or Improving user errors.

## Unicode support

While working on the Typst tree-sitter project, I've learned how extensive
Unicode is and the difficulty of correctly parsing such a language. In
particular, I learned how to work with all the weird cases of Unicode,
i.e., emojis, different types of Whitespace, and identifiers.

My main goal is to apply all the concepts I've learned with Typst to gcc-rs.

Thus, the main difficulties will be dealing with modifying the lexer to
handle \p{Whitespace}, \p{XID_Start}, and \p{XID_Continue} properly without
introducing complications in parsing in other areas of the project. Reusing
code from libcpp/ucnid.h from the CPP frontend may help with this part.
Finally, we must introduce a new Rust::String class that represents rust
identifiers, strings, and `create_name` instead of the old implementation.
Of course, I also need to define the v0 mangling scheme that Rust uses to
parse Unicode correctly. I can take a lot of inspiration from Tree-sitter.

The timeline is very close to the two proposals before me. However, I would
first start implementing punycode earlier as it would give me a checklist
on everything I must test to make the lexer fully support Unicode. As the
rest is then shifted, it makes it easier to implement tests for cases I
know will be difficult to deal with.


# Metadata
While working on the typst.nvim, I decided to use Rust to communicate to
Neovim's API  and Lua by linking binary to something neovim can use. This
piqued my interest, and from the looks of it, the work I would be doing in
this project would porting all the requirements of
`rustc_metadata::rmeta::CrateRoot` to `rust-export-metadata.cc`, whose spec
is detailed in `src/rustc_metadata/rmeta/encoder.rs`. In particular, I
would ensure that we support Strict Version Hash (SVH), Stable Crate Id,
and encoded MIR.

My timeline then is based on modifying and implementing the fields in
`CrateRoot.`

However generally:

Week 1-2:
- Modify rust-export-metadata.cc to include the "basic" fields in
CrateRoot, such as edition, panic_in_drop_strategy
- MetaItem

Week 3:
- Implement a testing method to load only specific metadata in case of
identical hashes correctly.
- Document all the functions I created

Week 4-5:
- Implement CrateDep
- Implement Strict Version Hash, which also needs:
- proper StableCrateId, which needs
- proper basic metadata support
Week 5-7:
- Implment `SourceFile`, `ForeignModule`, `NativeLib`, and the rest.
Week 8:
- Testing and documentation plus start a write-up.
Week 9-10:
- Pipelining and Crate loading
Week 11-12:
- Modify our rlib and add dylib support with compression

I would appreciate any mentor. I understand  I am still late, and this
email could be more robust; however, I would love to work on gcc-rs this
summer.

Thank you,
Charlie


-- 
Charlie Cruz -- Going through a name change!
Math & Linguistics @ Rice University '26
-- 
Gcc-rust mailing list
Gcc-rust@gcc.gnu.org
https://gcc.gnu.org/mailman/listinfo/gcc-rust